#1   Report Post  
Posted to microsoft.public.excel.programming
tjh tjh is offline
external usenet poster
 
Posts: 96
Default Protection

Hello,

I am trying to use the code below to protect all the tabs in an excel file
if the tab color has not been changed or appears grey. The code does not seem
to be checking every tab, it only works for the tab that is active and does
not continue to the next tabs. Can you please help me determine why it is not
working?

Thank you,

Dim wks As Worksheet

For Each wks In ActiveWorkbook.Worksheets
If wks.Tab.ColorIndex = xlColorIndexNone Then
ActiveSheet.Protect Password:=" ", DrawingObjects:=True,
Contents:=True, Scenarios:=True
Else
End If
Next wks

MsgBox "The Workbook is Protected"
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Protection

you need to select each sheet in turn

For Each wks In ActiveWorkbook.Worksheets
wks.select

Mike

"tjh" wrote:

Hello,

I am trying to use the code below to protect all the tabs in an excel file
if the tab color has not been changed or appears grey. The code does not seem
to be checking every tab, it only works for the tab that is active and does
not continue to the next tabs. Can you please help me determine why it is not
working?

Thank you,

Dim wks As Worksheet

For Each wks In ActiveWorkbook.Worksheets
If wks.Tab.ColorIndex = xlColorIndexNone Then
ActiveSheet.Protect Password:=" ", DrawingObjects:=True,
Contents:=True, Scenarios:=True
Else
End If
Next wks

MsgBox "The Workbook is Protected"

  #3   Report Post  
Posted to microsoft.public.excel.programming
tjh tjh is offline
external usenet poster
 
Posts: 96
Default Protection

Perfect, Thanks

"Mike H" wrote:

you need to select each sheet in turn

For Each wks In ActiveWorkbook.Worksheets
wks.select

Mike

"tjh" wrote:

Hello,

I am trying to use the code below to protect all the tabs in an excel file
if the tab color has not been changed or appears grey. The code does not seem
to be checking every tab, it only works for the tab that is active and does
not continue to the next tabs. Can you please help me determine why it is not
working?

Thank you,

Dim wks As Worksheet

For Each wks In ActiveWorkbook.Worksheets
If wks.Tab.ColorIndex = xlColorIndexNone Then
ActiveSheet.Protect Password:=" ", DrawingObjects:=True,
Contents:=True, Scenarios:=True
Else
End If
Next wks

MsgBox "The Workbook is Protected"

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default Protection

one way

Sub Protect_All_Sheets()
Dim i As Long
For i = 1 To Worksheets.Count
With Worksheets(i)
If .Tab.ColorIndex = xlColorIndexNone Then
.Protect
End If
End With
Next

End Sub



--


Gary


"tjh" wrote in message
...
Hello,

I am trying to use the code below to protect all the tabs in an excel file
if the tab color has not been changed or appears grey. The code does not seem
to be checking every tab, it only works for the tab that is active and does
not continue to the next tabs. Can you please help me determine why it is not
working?

Thank you,

Dim wks As Worksheet

For Each wks In ActiveWorkbook.Worksheets
If wks.Tab.ColorIndex = xlColorIndexNone Then
ActiveSheet.Protect Password:=" ", DrawingObjects:=True,
Contents:=True, Scenarios:=True
Else
End If
Next wks

MsgBox "The Workbook is Protected"



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel Data Protection Best Practice: AKA: Real Sheet Protection Mushman(Woof!)[_2_] Excel Discussion (Misc queries) 4 December 30th 09 01:20 AM
Excel Data Protection- AKA: Sheet/Macro Password Protection Mushman(Woof!) Setting up and Configuration of Excel 0 December 29th 09 06:50 AM
WS Protection: Different Levels of Protection on Different Ranges Carmi Excel Discussion (Misc queries) 4 August 31st 07 02:26 PM
Cell Protection vs. Worksheet Protection kmwhitt Excel Discussion (Misc queries) 4 September 24th 06 02:37 AM
Worksheet protection is gone and only wokbook protection can be se Eric C. Excel Discussion (Misc queries) 4 May 2nd 06 04:50 PM


All times are GMT +1. The time now is 09:09 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"