My macro does not work when I protect worksheet

tatertot

New Member
Joined
Apr 10, 2016
Messages
31
Hello All,

I have placed an ActiveX controls button in a worksheet that will perform a macro. I want to lock the worksheet so that users can only access the cells I designate and also run this macro to validate their data input.

My issue:
When I run the macro with worksheet locked, the macro runs. But if other users open the template, the macro will not run with the worksheet protected. How is this fixed?

If you need more details, please let me know! Thanks all for your assistance!!
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Unprotect it first...

Sheet.Unprotect("thepassword")

'do your code

Sheet.Protect("thePassword") 'check all args so you can lock it and give users proper functionality
 
Last edited:
Upvote 0
Hi Cerfani,

So would I put "Sheet.Unprotect(thepassword)" after Sub and "Sheet.Protect(thepassword)" after the macro has run?
 
Upvote 0
Correct... something like this...

Code:
Sub YourMacro()
    Workbook("workbookname.xlsx").Worksheets(1).Unprotect("password123")

    'put all your code here that edits this worksheet

    'make sure you set all the boolean arguments the way you like or else you use the default values
    Workbook("workbookname.xlsx").Worksheets(1).Protect("password123")
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,917
Members
452,366
Latest member
TePunaBloke

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