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.
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"
Related
Is there any way to check that is current cell in sheet has a bold border? I want to use this to separate areas
I only found how to change it, not to check. thats not cool
I have a table of contents in Excel 365. In the table, column 2 contains the names of worksheets and column 3 contains the names of tables and/or named ranges in the associated worksheet. I used the HYPERLINK function to link each cell to its specific component: hyperlinks for the worksheet column go to cell A1 on the associated worksheet; hyperlinks in the table/named range column go to that specific table or named range.
Since this results in several repeats of worksheet names, I used conditional formatting to change the text to white when the worksheet name is a repeat of the one directly above it. This makes it look more like an outline. It works like a charm up until the point that I click on the link in a repeated cell, making it a FollowedHyperlink. When I return to the table, this is no longer whited out. Is there a way to make these stay white, even after they've been followed?
Here's the formula I used for the conditional formatting rule applied it throughout the range =$C$6:$C$24:
=C5=C6
Here's what it looks like before I click one of the whited-out cells:
Here's what it looks like after I click one of the whited-out cells:
Urdearboy posted a link showing how to change the style of a followed link.
https://superuser.com/questions/728825/how-do-i-prevent-excel-from-changing-the-color-of-a-clicked-link/819931#819931
It is probably the best solution without using VBA.
But if you want some not control over it, if for example, you may want all links in a table if contents to be uniform color regardless if they were taken or not, but you want links in the rest of the book to change. That's as easy as a single line of VBA in the worksheet's SheetFollowHyperlink event:
Target.Range.Font.Color = vbBlue
And if you wanted to apply it to the entire workbook instead of a single sheet you would put it in the workbook's SheetFollowHyperlink event.
But if you want to be a little creative...
You could make the link disappear by blending it with the background color:
Target.Range.Font.Color = Target.Range.Interior.Color
Or you can draw attention to it, by changing the back color:
Target.Range.Interior.Color = vbYellow
Really, your imagination is the only limit. You can do just about anything you'd ever want to do ( and a lot more of things you would never want to do).
I have a form that opens and highlights certain highly formatted rows.
The highlighting is done by selecting those rows, so they are colored light blue.
When the form closes, the rows are still selected, and that's good. The formatting beneath the selection isn't disturbed so if the user clicks anywhere on the worksheet, all the original formatting is intact.
My question is can I select rows and highlight them in a color besides standard blue (bright pink) so the user can see them more easily? I don't want to have to reformat the interior colors, and then try to figure out how to unformat them when the user is done noticing them.
sRowsToHighlight = "196:196,201:201,203:203"
m_wksPST.Range(sRowsToHighlight).Select ' Turns them blue, but I want a bright color
After my code is done, I would want selection to revert to the standard Excel color scheme.
Thanks!
I would be surprised if you could do that without manually coding it yourself. The selection colour is an application setting. You could change it in Excel, but that will change it for the whole of excel on that computer (i.e. any worksheets that get opened) and also it wouldn't help if your users are using this spreadsheet on a different computer. But here is a link anyway: http://en.kioskea.net/faq/8703-excel-changing-the-highlighting-color-of-selected-cells
I ran into a peculiar behavior today that I need help with. I have a range(A2:C3) that I'm using conditional formatting to hide based on a yes/no dropdown (A1). It basically sets font/border/and bg color to white. There's a cell with a hyperlink (A3) to clear the contents of the range (A2:C3) which should be included when the range formatting is changed.
It works well until you click the link, then it isn't included with the range for conditional formatting for some reason. Any ideas on a solution to get followed hyperlinks to behave as new hyperlinks? I'd like to keep everything within the conditional formatting scheme to save myself a heap of work but if VBA is needed that's fine. Thanks!
Select the column, row or cells.
Format Cells
Uncheck normal font.
:)
This deselects auto formating for things like hyper links.
I can't for the life of me figure out why certain cells are shaded in a spreadsheet template I downloaded. I confirmed that the cell's shading property is set to no color. The cell has a simple formula: =SUM(J8:K8).
If the background color is being set by code in another cell, I'm not sure how to find it. Searching for the cell name (ex: B7) doesn't come up with anything. Any suggestions what could be setting the background color?
Have you had a look at the Conditional Formating options?
It could be that there's a background colour set in there.
In Office 2007 it's on the Ribbon in the Styles section on the Home tab - your best bet is to go for the "Manage Rules..." option, and then check the rules for each worksheet.