Password Property

Microsoft Excel Visual Basic

expression.Password

expression    Required. An expression that returns one of the objects in the Applies To list.

Example

In this example, Microsoft Excel opens a workbook named Password.xls, sets a password for it, and then closes the workbook. This example assumes a file named "Password.xls" exists on the C:\ drive.

Sub UsePassword()

    Dim wkbOne As Workbook
    
    Set wkbOne = Application.Workbooks.Open("C:\Password.xls")

    wkbOne.Password = InputBox ("Enter Password")
    wkbOne.Close

End Sub
		

Note  The Password property is readable and returns ">>**".