VBA - Read-only Tab Font Color

dhancy

Board Regular
Joined
Jul 10, 2013
Messages
120
Office Version
  1. 2016
Platform
  1. Windows
Hello,

I have seen articles saying that we cannot change a tab font color in VBA. Excel will automatically determine the font color based on the background color selected.

But is it possible to read the font color of a tab?

Thanks,
Dennis
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Thanks, but isn't that the background color of the tab, and not the font color?
 
Upvote 0
As far as I know, there is no way of finding the font colour.
Why do you ask?
 
Upvote 0
I have a request to duplicate the colour scheme on a given tab in a given range of cells on a worksheet.

As you noted, reading the tab's background colour is straightforward (activesheet.tab.color). However we have some tabs with a black background. When I duplicate that in a range of cells, the font colour is still black, making it impossible to read. I was hoping to read the tab's font colour as well so I could apply that to the range of cells also.
 
Upvote 0
No worries.. Appreciate you taking time to respond :) And I see I was also being inattentive. I "assumed" the second person to respond to this was you, but now I see it is someone else. It's going to be one of those days.. LOL
 
Upvote 0
Ok, you could use this function by @Rick Rothstein
VBA Code:
Function TextColorToUse(BackColor As Long) As Long

'  This function returns the color to use for
'  text to make it readable on a dark background
'  Code by of Rick Rothstein
  Dim Luminance As Long
  Luminance = 77 * (BackColor Mod &H100) + _
              151 * ((BackColor \ &H100) Mod &H100) + _
              28 * ((BackColor \ &H10000) Mod &H100)
  '  Default value of TextColorToUse is 0-Black, set
  '  it to White if the Luminance is less than 32640
  If Luminance < 32640 Then TextColorToUse = vbWhite
End Function
And use it like
VBA Code:
Sub dhancey()
With Range("A1:C20")
   .Interior.Color = .Parent.Tab.Color
   .Font.Color = TextColorToUse(.Parent.Tab.Color)
End With
End Sub
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,385
Messages
6,119,205
Members
448,874
Latest member
Lancelots

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
Back
Top