Workbook.ProtectSharing Method (Excel)

Saves the workbook and protects it for sharing.

Syntax

expression .ProtectSharing(Filename, Password, WriteResPassword, ReadOnlyRecommended, CreateBackup, SharingPassword, FileFormat)

expression A variable that represents a Workbook object.

Parameters

Name

Required/Optional

Data Type

Description

Filename

Optional

Variant

A string indicating the name of the saved file. You can include a full path; if you don’t, Microsoft Excel saves the file in the current folder.

Password

Optional

Variant

A case-sensitive string indicating the protection password to be given to the file. Should be no longer than 15 characters.

WriteResPassword

Optional

Variant

A string indicating the write-reservation password for this file. If a file is saved with the password and the password isn’t supplied when the file is opened, the file is opened read-only.

ReadOnlyRecommended

Optional

Variant

True to display a message when the file is opened, recommending that the file be opened read-only.

CreateBackup

Optional

Variant

True to create a backup file.

SharingPassword

Optional

Variant

A string indicating the password to be used to protect the file for sharing.

FileFormat

Optional

Variant

A string indicating the file format.

Remarks

Use strong passwords that combine uppercase and lowercase letters, numbers, and symbols. Weak passwords don't mix these elements. Strong password: Y6dh!et5. Weak password: House27. Passwords should be 8 or more characters in length. A pass phrase that uses 14 or more characters is better. For more information, see Help protect your personal information with strong passwords. It is critical that you remember your password. If you forget your password, Microsoft cannot retrieve it. Store the passwords that you write down in a secure place away from the information that they help protect.

Example

This example saves workbook one and protects it for sharing.

 
Sub ProtectWorkbook() 
 
    Dim wbAWB As Workbook 
    Dim strPwd As String 
    Dim strSharePwd As String 
 
    Set wbAWB = Application.ActiveWorkbook 
 
    strPwd = InputBox("Enter password for the file") 
    strSharePwd = InputBox("Enter password for sharing") 
 
    wbAWB.ProtectSharing Password:=strPwd, _ 
        SharingPassword:=strSharePwd 
 
End Sub 

See Also

Concepts

Workbook Object

Workbook Object Members