Tab Object Example

The following routine changes the tab color for all budget worksheets in a workbook based on a setting in a custom property for each worksheet:

Sub ColorBudgetTabs()

Dim bBudget As Boolean Dim oCustomProp As CustomProperty Dim oCustomProps As CustomProperties Dim wks As Worksheet

'Loop through each worksheet in this workbook For Each wks In ThisWorkbook.Worksheets

'Loop through all of the custom properties ' for the current worksheet until the ' "IsBudget" property name is found For Each oCustomProp In wks.CustomProperties If oCustomProp.Name = "IsBudget" Then 'Grab its value and exit the loop bBudget = CBool(oCustomProp.Value) Exit For End If Next oCustomProp

'Use the value in the custom property to determine

' whether the tab should be colored.

If bBudget Then wks.Tab.ColorIndex = 20 'Light blue

Next wks

End Sub

0 0

Post a comment