Workbook.ProtectSharing method (Excel)
Saves the workbook and protects it for sharing.
expression.ProtectSharing (FileName, Password, WriteResPassword, ReadOnlyRecommended, CreateBackup, SharingPassword, FileFormat)
expression A variable that represents 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.|
|FileFormat||Optional||Variant||A string indicating the file format.|
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. 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.
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
Support and feedback
Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.