gl3nnyb0y24
New Member
- Joined
- May 8, 2019
- Messages
- 6
How to close/exit VBA Form if conditions are success;
(unprotect all sheets with a password)
- I created a form for Inputting passwords to unprotect all sheets
- Then click the Submit button to execute the code
If the password is correct the form did close, how do I close the form if the password is correct?
Thank you!
(unprotect all sheets with a password)
- I created a form for Inputting passwords to unprotect all sheets
- Then click the Submit button to execute the code
If the password is correct the form did close, how do I close the form if the password is correct?
Thank you!
VBA Code:
Private Sub cmdInput_Click()
Dim ws As Worksheet
Dim pwd As String
pwd = txtPassword.Value
On Error Resume Next
For Each ws In Worksheets
ws.unprotect Password:=pwd
Next ws
If Err <> 0 Then
MsgBox "You have entered an incorrect password. Please check your password."
On Error GoTo 0
End If
End Sub