Unprotect all worksheets vba doesn't work

Apple08

Active Member
Joined
Nov 1, 2014
Messages
450
Hi All

I have a workbook with a number of worksheets which might have been protected or not protected by users. I have created the macro below to unprotect all worksheets, however I got the error message:

Run-time error '1004':
Mthod 'Unprotect' of object'_Worksheet' failed


VBA Code:
Sub Unprotect()

Dim ws As Worksheet

    For Each ws In Worksheets
        ws.Unprotect
    Next ws

End Sub

Please could anyone help? Many thanks.
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Are any of the worksheets protected with passwords? That will give you the error.
 
Upvote 0
Thanks Jeff, it makes sense to me now. Please am I able to unprotect specific worksheets from the workbook? I require to unprotect 'Sheet 1" to "Sheet 5" as they are only protected without a password.
 
Upvote 0
Update the names of the sheets I used to your actual sheet names.
VBA Code:
Sub Unprotect()

   Dim S As Variant

   For Each S In Array("Sheet 1", "Sheet 2", "Sheet 3", "Sheet 4", "Sheet 5")
      Worksheets(S).Unprotect
   Next S

End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,214,626
Messages
6,120,602
Members
448,974
Latest member
ChristineC

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