Difficulty: Running macro in pw protected worksheet

timesareGMT

New Member
Joined
Aug 19, 2011
Messages
26
Hi all,

Here I have a difficulty of running macro in a password protected worksheet.

The VBA code is that:

Sub Checker()<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<o:p></o:p>
Dim r As Long, cb As CheckBox<o:p></o:p>
<o:p></o:p>
Set cb = ActiveSheet.CheckBoxes(Application.Caller)<o:p></o:p>
r = Range(cb.LinkedCell).Row + 11<o:p></o:p>
<o:p></o:p>
Sheets("Report Layout").Rows(r).Hidden = cb.Value = xlOff<o:p></o:p>
<o:p></o:p>
End Sub<o:p></o:p>
<o:p></o:p>
<o:p></o:p>
<o:p>When I run the above macro under the pw protected condition, the following message appears: </o:p>
<o:p></o:p>
<o:p>Run-time error '1004': </o:p>
<o:p></o:p>
<o:p>Unable to set the Hidden property of the Range class </o:p>
<o:p></o:p>
<o:p></o:p>
<o:p>Is there a solution to get it fixed? </o:p>
<o:p></o:p>
<o:p>Thanks. </o:p>
<o:p></o:p>
<o:p></o:p>
<o:p></o:p>
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p>Is there a solution to get it fixed? </o:p>

Offhand I'd say yes, that being to unprotect the sheet and then reprotect it in the code, unless there is more to your question than you posted.

I imagine the sheet that is protected is Report Layout, so for that part of your macro you could do this, modifying for whatever your actual password is:

Code:
With Sheets("Report Layout")
.Unprotect ("YourPassword")
.Rows(r).Hidden = cb.Value = xlOff
.Protect ("YourPassword")
End With
 
Upvote 0
Offhand I'd say yes, that being to unprotect the sheet and then reprotect it in the code, unless there is more to your question than you posted.

I imagine the sheet that is protected is Report Layout, so for that part of your macro you could do this, modifying for whatever your actual password is:

Code:
With Sheets("Report Layout")
.Unprotect ("YourPassword")
[COLOR=blue]Sheets("Report Layout").[/COLOR]Rows(r).Hidden = cb.Value = xlOff
[COLOR=blue]Sheets("Report Layout").[/COLOR]Protect ("YourPassword")
End With


Thanks, it works with adding additional info (highlighted blue) to your code!

Thanks again.:)
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,728
Members
452,939
Latest member
WCrawford

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