Protecting worksheet

lbonsemb

New Member
Joined
Aug 11, 2002
Messages
18
If I protect a sheet through Tools/Protection, a button that runs a macro to hide rows cannot be executed without having to enter the password to unprotect it (which defeats the purpose of protecting the worksheet).
I know there is a way to protect through coding. Please give me a hand to solve this.
Thanks
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Is this what you need...

'To protect the sheet place this at the bottom of your macro...
ActiveSheet.Protect DrawingObjects:=True,
Contents:=True, Scenarios:=True

'To unprotect the active sheet...place this at the top of you macro...


ActiveSheet.Unprotect

I hope this helps you.

David
 
Upvote 0
Is this what you need...

'To protect the sheet place this at the bottom of your macro...
ActiveSheet.Protect DrawingObjects:=True,
Contents:=True, Scenarios:=True

'To unprotect the active sheet...place this at the top of you macro...


ActiveSheet.Unprotect

I hope this helps you.

David
 
Upvote 0
Is this what you need...

'To protect the sheet place this at the bottom of your macro...
ActiveSheet.Protect DrawingObjects:=True,
Contents:=True, Scenarios:=True

'To unprotect the active sheet...place this at the top of you macro...


ActiveSheet.Unprotect

I hope this helps you.

David
 
Upvote 0
here is code to protect and unprotect a single worksheet through vba

To protect multiple sheets use For Each statement.

To protect single:

Sub Protect()
Dim mySheet As Worksheet
Set mySheet = Worksheets("Project WorkSheet")
mySheet.Protect "SIMONE", True, True
End Sub

To Unprotect single:

Sub UnProtect()
Dim mySheet As Worksheet
Set mySheet = Worksheets("Project WorkSheet")
mySheet.Unprotect "SIMONE"
End Sub

you can put this code behind a command button
or put it inline with your current code.

Hope this helps!

Dan
 
Upvote 0
here is code to protect and unprotect a single worksheet through vba

To protect multiple sheets use For Each statement.

To protect single:

Sub Protect()
Dim mySheet As Worksheet
Set mySheet = Worksheets("Project WorkSheet")
mySheet.Protect "SIMONE", True, True
End Sub

To Unprotect single:

Sub UnProtect()
Dim mySheet As Worksheet
Set mySheet = Worksheets("Project WorkSheet")
mySheet.Unprotect "SIMONE"
End Sub

you can put this code behind a command button
or put it inline with your current code.

Hope this helps!

Dan
 
Upvote 0

Forum statistics

Threads
1,223,493
Messages
6,172,618
Members
452,466
Latest member
Lynlindsay

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