mercredi 10 juillet 2019

How to require password to terminate a userform in VBA

I want to prevent the user from closing the form and editing the spreadsheet if they don't know the password. I can get the Userform to stay open but I cannot figure out how to initialize the form so all of the command buttons still function.

I have tried using an if statement as described below. The userform stays open but isn't initialized so the user is unable to enter a password or run the userform at all.

Private Sub UserForm_Terminate()

    Password = InputBox("Enter Password")
    If Password = "syntax" Then
        UserForm1.Hide
    ElseIf Password <> "syntax" Then
        UserForm1.Show
    End If
    End

End Sub

There aren't any error messages, but if the VBA editor window isn't open the user has to close Excel completely. Any advice on what to try next is appreciated. Thanks in advance

Aucun commentaire:

Enregistrer un commentaire