Unprotect All Sheet

RandyD123

Active Member
Joined
Dec 4, 2013
Messages
289
Office Version
  1. 2016
Platform
  1. Windows
I am currently using the code below. I want to stop the "vbCritical" error if I CANCEL the password input box. I would like it to just exit and do nothing. What am I missing?

Code:
 Sub UnProtectAll()
 
     'Use Ctl+Shift+U To Unlock All Sheets
     
    Dim ws As Worksheet
    Dim strPwd As String
    Dim strCheck As String
Application.ScreenUpdating = False
   strCheck = "mypassword"
     strPwd = InputBox("Enter Password", "Password", "Enter Password")
If strPwd = strCheck Then
  For Each ws In ThisWorkbook.Worksheets
     ws.Unprotect Password:=strPwd
  Next ws
  Else
        MsgBox "Incorrect Password", vbCritical, "Incorrect Password"
  End If
Application.ScreenUpdating = True
End Sub

Thanks in advance!!
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Hi, you could try adding this line directly after the strpwd = inputbox(.. line of code.

If strPwd = "" Then Exit Sub
 
Upvote 0
Hi, that really doesn't give us a lot to go on to help you troubleshoot!

Can you post your amended code?

Code:
 Sub UnProtectAll()
 
     'Use Ctl+Shift+U To Unlock All Sheets
     
    Dim ws As Worksheet
    Dim strPwd As String
    Dim strCheck As String
Application.ScreenUpdating = False
   strCheck = "mypassword"
     strPwd = InputBox("Enter Password", "Password", "Enter Password")
If strPwd = "" Then Exit Sub
  For Each ws In ThisWorkbook.Worksheets
     ws.Unprotect Password:=strPwd
  Next ws
  Else
        MsgBox "Incorrect Password", vbCritical, "Incorrect Password"
  End If
Application.ScreenUpdating = True
End Sub

I errors out right away with the modified "If strPwd = strCheck Then"
 
Upvote 0
Yep, that worked. Sorry for not understanding the first reply. Thank You!!!
 
Upvote 0

Forum statistics

Threads
1,216,776
Messages
6,132,660
Members
449,744
Latest member
kauamarcosms

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