Protection

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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"
 
you need to select each sheet in turn

For Each wks In ActiveWorkbook.Worksheets
wks.select

Mike
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top