ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Protection (https://www.excelbanter.com/excel-programming/391215-protection.html)

tjh

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"

Mike H

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"


tjh

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"


Gary Keramidas

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"





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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com