Home

excel protect

Marc_Mes
New Contributor

Hello,

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
Highlighted

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.

 

Marc.

Netherlands

Hi, have you written much vba before?

Are you getting an error message?

Related Conversations
Tabs and Dark Mode
cjc2112 in Discussions on
50 Replies
Extentions Synchronization
Deleted in Discussions on
3 Replies
Stable version of Edge insider browser
HotCakeX in Discussions on
35 Replies
How to Prevent Teams from Auto-Launch
chenrylee in Microsoft Teams on
32 Replies
Security Community Webinars
Valon_Kolica in Security, Privacy & Compliance on
15 Replies
Dev channel update to 80.0.355.1 is live
josh_bodner in Discussions on
67 Replies