Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing color of tabs in Excel using VBA?

Tags:

excel

vba

I have script I created that creates a new sheet, and a new tab in said sheet, before changing the names of said tabs, I want to make it so Sheet1 through Sheet4 all are red.

With wbBK2.Sheets(wsWS1).Tab
    .Color = 255
End With

Now the code above works for individual tabs, but I am wondering is there a way to change all four tabs at the same time using Excel VBA?

like image 376
Matt Ridge Avatar asked Sep 17 '12 17:09

Matt Ridge


1 Answers

Try something like this:

Dim Sht As Worksheet
For Each Sht In Application.Worksheets
    With Sht.Tab
        .Color = 255
    End With
Next Sht

Note:

I think you may be able to change Application.Worksheets to wbBK2.Worksheets, but I'm running too low on caffeine to remember, or time to test it.

like image 95
danielpiestrak Avatar answered Oct 06 '22 02:10

danielpiestrak