protection

Cossie

Active Member
Joined
May 6, 2002
Messages
328
I have a series of sheet and graphs as sheet tabs in the same work book and i would like the macro code to protect and unprotect them all rather than just the worksheets. I use

For Each ws in Sheets
ws.protect Password:="password"
Next ws
End sub

Thanks
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
this is code from NateO

Sub alShts2()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
ws.Protect "password" 'change 'protect' to 'unprotect' to unprotect each sheet
Next ws
End Sub
 
Upvote 0
that works for the worksheets but stops at the charts tabs.

Is there soemthing missing?
 
Upvote 0
Qroozn, I appreciate the reference, seems like a long time ago that you and I were talking about flashing cells on the old board....

To the matter at hand. Try:

Code:
Sub alShts3() 
Dim ws As Worksheet 
For Each ws In ThisWorkbook.Worksheets 
ws.Protect "password" 'change 'protect' to 'unprotect' to unprotect each sheet 
Next ws
For Each ws In ThisWorkbook.Charts
ws.Protect "password" 'change 'protect' to 'unprotect' to unprotect each sheet 
Next ws
End Sub

Chart sheets and normal worksheets carry different properties, making them finicky. Have a good one y'all.


_________________
Cheers,<font size=+2><font color="red"> Nate<font color="blue">O</font></font></font>
wave.gif

This message was edited by NateO on 2002-05-08 21:43
 
Upvote 0
Bad variable. Try:

Code:
Sub Pro()
Dim ws As Worksheet, ch As Chart
For Each ws In ThisWorkbook.Worksheets
ws.Protect "ps"
Next ws
For Each ch In ThisWorkbook.Charts
ch.Protect "ps"
Next ch
End Sub

Sorry 'bout the goof.
 
Upvote 0

Forum statistics

Threads
1,214,523
Messages
6,120,031
Members
448,940
Latest member
mdusw

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