4
votes

How can I get the current Fill Color in the ribbon using VBA? I like to manually select the Fill color to highlight entire rows with. I know I can highlight an entire row with code like foo.EntireRow.Interior.ColorIndex = 3. However, instead of setting it to 3, I want to set it to the user's currently selected Fill Color in the ribbon.

I found a similar thread for Microsoft Word that uses Options.DefaultHighlightColorIndex, but I have not found one for Microsoft Excel.

Edit: Sorry for the duplicate question. I am hoping there’s a better answer that doesn’t require an active selection first. If not I’ll accept Jonathan’s answer. Currently I am just highlighting the current cell with CellFillColorPicker, getting that cell’s color and then highlighting the row with that color.

1
I only know of a way where you need to select the range first and then execute: Application.CommandBars.ExecuteMso "CellFillColorPicker" - Alex de Jong

1 Answers

1
votes

This question appears to be similar to this one: VBA - use color already select in Excel to fill cell interior

It looks like this is the code that you want:

Application.CommandBars.ExecuteMso "CellFillColorPicker"