Incorporate Unlocking All Sheets Into Macro

AllDay

New Member
Joined
Jul 28, 2016
Messages
12
Right now I have a button that refreshes multiple queries over multiple worksheets in the same workbook. These worksheets are all protected and my macro will not update those queries due to the protection.

I added a two additional buttons to unprotect all sheets and protect all sheets.

Can I add those two modules into my original so when I click the original button it would unprotect all sheets, run my VBA, then reprotect all the sheets?
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
If you loop through your sheets to perform certain tasks on each one, you can unprotect/protect each sheet as you go through the loop:
Code:
Sub Test()
    Dim ws As Worksheet
    For Each ws In Sheets
        ws.Unprotect
        'your code here
        ws.Protect
    Next ws
End Sub
This would eliminate the need for any buttons or additional macros to protect and unprotect.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,306
Members
452,633
Latest member
DougMo

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