excel protect

New Contributor


I like to protect an excel worksheet for opening with a password, but it have to work just after a while. So, i give a worksheet to some one, and he or she can use it for, example, a month. After a month a password is neccecary to open the sheet. How can i make that? I think it is possible with VBA.

Gr. Marc.

3 Replies

Something like this


Private Sub Workbook_Open()

Dim ExpiryDate As String
Dim pwd As String

pwd = "ABC"
ExpiryDate = "28/01/2019"

If Date > ExpiryDate Then

    MsgBox "Password has expired", vbCritical, "Expired Password!"
    If InputBox("Enter Password", "", "") <> pwd Then
     'enter a close or repeat password routine here
        MsgBox "Close"
        Exit Sub
    End If
End If

End Sub

I think i need more help, because het won't work. I probebly make a mistake.




Hi, have you written much vba before?

Are you getting an error message?

Related Conversations
Version 2001 Excel 365 and no Dynamic Arrays
MilesWilliams in Excel on
5 Replies
$ symbol changes format of cells automatically
gbetar01 in Excel on
2 Replies
Excel table formatting best practices question
Jerry1385 in Excel on
2 Replies
If/Then Formula Not Drawing Across Sheets
Matt010614 in Excel on
2 Replies
enaugle in Excel on
3 Replies
how to calculate sum of the previous months by company
gorandimeski in Excel on
1 Replies