Set Workbook Password : Workbook Password « Excel « VBA / Excel / Access / Word






Set Workbook Password

 
Sub SetWorkbookPassword()
    Dim myWorkbook As Workbook, pass As String
    Set myWorkbook = ThisWorkbook
    pass = "Password"
    If pass = "Password" Then
        myWorkbook.Password = pass
        Debug.Print "Password set."
    Else
        Debug.Print "Passwords don't match. No password set."
    End If
End Sub

 








Related examples in the same category

1.Clear password
2.Write Password