Name

workbook.ProtectSharing([Filename], [Password], [WriteResPassword], [ReadOnlyRecommended], [CreateBackup], [SharingPassword])

Synopsis

Saves a file for sharing and optionally sets protection, read-only, and read/write passwords.

Argument

Settings

Filename

The name to save the file as. When saving a workbook for sharing, it is common to save the file to a new (public) location.

Password

The password used to open the workbook.

WriteResPassword

The password used to open the workbook for read/write access.

ReadOnlyRecommended

True displays a prompt recommending that the workbook be opened for read-only access when the user opens the workbook in Excel; False does not prompt. Default is False.

CreateBackup

True automatically creates a backup version of the file before saving the file and sharing it; False does not create a backup. Default is False.

SharingPassword

The password used to remove sharing from the workbook.

The many password arguments for the ProtectSharing method can be confusing. The following code saves a workbook to a public location and sets three passwords for the file:

    Set wb = ThisWorkbook
    wb.ProtectSharing "\\wombat1\public\shared.xls", "pass1", "pass2", , , "pass3"

Once the preceding code runs, you use "pass1" to open the file, "pass2" to get read/write access to the file, and "pass3" to remove file sharing from the file.

Get Programming Excel with VBA and .NET now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.