ProtectSharing Method

Microsoft Excel Visual Basic

Saves the workbook and protects it for sharing.

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

expression    An expression that returns a Workbook object.

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.

Note  Use strong passwords that combine upper- and lowercase letters, numbers, and symbols. Weak passwords don't mix these elements. Strong password: Y6dh!et5. Weak password: House27. Use a strong password that you can remember so that you don't have to write it down.

Example

This example saves workbook one and protects it for sharing.


Sub ProtectWorkbook()

    Dim wksOne As Worksheet
    Dim strPwd As String
    Dim strSharePwd As String

    Set wksOne = Application.ActiveSheet

    strPwd = InputBox("Enter password for the file")
    strSharePwd = InputBox("Enter password for sharing")

    wksOne.ProtectSharing Password:=strPwd, _
        SharingPassword:=strSharePwd

End Sub