Simple Question - VBA Object Name

Benzula

Board Regular
Joined
Feb 28, 2014
Messages
248
What is the VBA Object name for selecting the active sheets' tab to change its color.

Basically I want to change the color of a tab on a simple loop, but I can't select the active Tab.

Code:
Dim sheetNo As Integer


For sheetNo = 1 To Sheets.Count
   Sheets(sheetNo).Activate
    
ActiveSheet.ActivateTab.Select
    With ActiveTab
        .ThemeColor = xlThemeColorAccent2
        .TintAndShade = 0.399975585192419
    End With
    Next
End Sub
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN

Michael M

Well-known Member
Joined
Oct 27, 2005
Messages
21,586
Office Version
  1. 365
  2. 2019
  3. 2013
  4. 2007
Platform
  1. Windows
Maybe something like
Code:
Sub MM1()
Dim Sht As Worksheet
For Each Sht In Worksheets
    With Sht.Tab
        .Color = 255
    End With
Next Sht
end sub
 
Upvote 0

Momentman

Well-known Member
Joined
Jan 11, 2012
Messages
4,142
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Something like this, changes the colour of the active sheet tab to RED
Code:
Sub activesheetcolour()
    Dim ws As Worksheet
    Set ws = ActiveWorkbook.ActiveSheet
    ws.Tab.Color = vbRed
End Sub

or in a loop
Code:
Sub activesheetcolour()
    Dim ws As Worksheet
    For Each ws In ActiveWorkbook.Worksheets
        ws.Tab.Color = vbRed
    Next ws
End Sub
 
Last edited:
Upvote 0

gardnertoo

Well-known Member
Joined
Jul 24, 2007
Messages
938
This worked for me in Excel 2010. No need to activate the sheets either, I commented that line out:

Code:
Dim sheetNo As Integer
For sheetNo = 1 To Sheets.Count
   'Sheets(sheetNo).Activate
    With ActiveWorkbook.Sheets(sheetNo).Tab
        .ThemeColor = xlThemeColorAccent2
        .TintAndShade = 0.399975585192419
    End With
Next sheetNo
 
Upvote 0

Forum statistics

Threads
1,190,663
Messages
5,982,158
Members
439,762
Latest member
RoryJ80

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top