View Full Version : Solved: Noob question

05-23-2009, 09:38 AM
I've got following code that I cant seem to get to work. This is proablably very easy since I am very new at this VBA programming.


Option Explicit
Private Sub CommandButton1_Click()
Dim ws As Worksheet
Dim passw As String
Dim confirmpassw As String
passw = passwbox.Text

For Each ws In Worksheets
If ws.ProtectContents = True Then
ws.Unprotect Password:=passwbox.Text


confirmpassw = InputBox("Confirm your password by re-entering:", "Password confirmation")
If passw <> confirmpassw Then
MsgBox ("Passwords does not match! Please try again.")
ws.protect Password:=passw
End If
End If
Unload Me
Next ws

End Sub

05-23-2009, 11:24 AM
You don't say what is not working, but perhaps you are unloading the form too early, try doing after the Next ws.