Skip to content

Latest commit

 

History

History
73 lines (46 loc) · 2.67 KB

Excel.Workbook.ProtectSharing.md

File metadata and controls

73 lines (46 loc) · 2.67 KB
title keywords f1_keywords api_name ms.assetid ms.date ms.localizationpriority
Workbook.ProtectSharing method (Excel)
vbaxl10.chm199265
vbaxl10.chm199265
Excel.Workbook.ProtectSharing
26660bc6-136a-ffc8-987e-c96db9c08231
05/29/2019
medium

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. It's 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

[!includeSupport and feedback]