PROTECT: User Interface Only not working

hensleyj

New Member
Joined
Apr 2, 2012
Messages
39
Hey guys,

Im having problems with my sheets being protected and macro's not working. I attempted to use the interfaceonly option however it doesnt seem to be working.

My code is below. It prompts me for the password and works fine. However when i run a macro, it doesnt work.

Can anyone see what is going wrong with this? The macro's being run are triggered by a worksheet change event....is this why the userinterface is not working?

Any help would be apprecaited

Code:
Sub sbProtectAllSheets()Dim pwd1 As String, pwd2 As String
pwd1 = InputBox("Please Enter the password")
If pwd1 = "" Then Exit Sub
pwd2 = InputBox("Please re-enter the password")
If pwd2 = "" Then Exit Sub
'Check if both the passwords are identical
If InStr(1, pwd2, pwd1, 0) = 0 Or _
InStr(1, pwd1, pwd2, 0) = 0 Then
MsgBox "You entered different passwords. No action taken"
Exit Sub
End If
For Each ws In Worksheets
ws.Protect Password:=pwd1, UserInterfaceOnly:=True
Next
MsgBox "All sheets Protected."
Exit Sub
End Sub
 

Takae

Well-known Member
Joined
Jul 1, 2015
Messages
674
Does worksheet change event have a "Application.EnableEvents = False" ?
If it has please try put "Application.EnableEvents = True" in before Exit sub.

If pwd1 = "" Then
Application.EnableEvents = True
Exit Sub
 

Forum statistics

Threads
1,085,047
Messages
5,381,373
Members
401,735
Latest member
ranjithr

Some videos you may like

This Week's Hot Topics

Top