Bypassing protection dialog box

Paella1

Active Member
Joined
Mar 10, 2005
Messages
382
This procedure loops through each worksheet unhiding and unprotecting each one:

Code:
Sub unprotectunhideall()

Dim i As Integer
Dim noshts, areis As String


For Each sht In Worksheets
    
    Application.DisplayAlerts = False
    sht.Unprotect
    Application.DisplayAlerts = True
    If sht.ProtectContents = True Then i = i + 1
    sht.Visible = True

Next sht

If i = 1 Then
    noshts = " sheet "
    areis = " is "
End If
If i > 1 Then
    noshts = " sheets "
    areis = " are "
End If

If i > 0 Then MsgBox (i & noshts & areis & "password protected.")

End Sub

The intention of temporarily setting Application.DisplayAlerts to False was to stop the password dialog box from popping up. I would prefer that the procedure just continued, because in the event that some sheets are protected, the user is advised by the msgbox at the end.

Is there a way I can test whether a sheet is password protected, or
Is there a method of preventing the password box from displaying?
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Get rid of the DisplayAlerts. They don't do anything.

You could use sht.Unprotect Password:="".

That will unprotect a worksheet with no password but will error on a worksheet with a password.

On error resume next

will get the code over the passwords.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,560
Messages
6,179,520
Members
452,923
Latest member
JackiG

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top