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