How to Change Sheet Tab Color in Excel Add-in? with code example

How to Change Sheet Tab Color in Excel Add-in? with code example

Tab

Object exposed Color and ColorIndex property which can be set to change Sheet Tab color. Tab object exposed by Sheet object.

Code example

Public Sub ChangeTabColorExample()
    Dim oSheet As Worksheet
    Set oSheet = Worksheets("Sheet1")
    'Set first sheet color
    oSheet.Tab.Color = vbRed
    'Set first sheet Blue
    Set oSheet = Worksheets("Sheet2")
    oSheet.Tab.Color = vbBlue
    
    'Set first sheet Yellow
    Set oSheet = Worksheets("Sheet3")
    oSheet.Tab.Color = vbYellow

    'Set first sheet Black
    Set oSheet = Worksheets("Sheet4")
    oSheet.Tab.Color = vbBlack

    'Cleanup
    If Not oSheet Is Nothing Then
        Set oSheet = Nothing
    End If
End Sub

Output

Next >> Format as Table Style in Excel with code example

Leave a Reply

Your email address will not be published.