Share via


Workbook.WritePassword Property

Excel Developer Reference

Returns or sets a String for the write password of a workbook. Read/write.

Syntax

expression.WritePassword

expression   A variable that represents a Workbook object.

Example

In this example, if the active workbook is not protected against saving changes, Microsoft Excel sets the password to a string as the write password for the active workbook.

Visual Basic for Applications
  Sub UseWritePassword()
Dim strPassword As String

strPassword = InputBox ("Enter the password")

' Set password to a string if allowed.
If ActiveWorkbook.WriteReserved = False Then
    ActiveWorkbook.<strong class="bterm">WritePassword</strong> = strPassword
End If

End Sub

See Also