F
Fede Sauret
Hi,
I've been trying to find a way to do this, but couldn't find enough
information out there. So sorry if this was already explained
somewhere else. I also hope am asking in the right place.
I have added a custom ribbon tab in an add-in. One of the controls
will consist of 9 small buttons, each button changes the active cell
background to a specific color. This way I expect we'll be saving some
time. My problem is that by changing the color this way (using a VBA
macro) I loose the possibility of undoing the changes. So I was
wondering if it would be possible to simulate the click of the user in
the color filler button that comes in the default Excel ribbon at the
Font group in the Home tab.
After a few hours trying it I could do something similar with:
Application.CommandBars.ExecuteMso ("CellFillColorPicker")
But this solution doesn't allow to undo. Also I couldn't find a way to
change the selected color, so it would be pretty much useless.
I also tried accessing the control doing:
Dim CBR As CommandBar
Set CBR = Application.CommandBars("Fill color")
Dim colControl As CommandBarControl
Set colControl = CBR.Controls(3) 'This three is in order to
access one of the buttons in the bar, in this case, "Standard colors".
But I also tried the rest.
colControl.Execute
But this code's "colControl.execute" doesn't do anything. I guess it's
because I am accessing a CommandBarControl, not a CommandBarButton,
but I didn't find a way to do it. I did though find a way to format
the text bold:
Dim CBR As CommandBar
Set CBR = Application.CommandBars("Formatting")
Dim bold As CommandBarButton
Set bold = CBR.Controls(3)
bold.Execute
And again, this option doesn't allow undoing actions.
So, how should I do it?
Thanks a lot in advance and I hope I explained myself!
Fede
I've been trying to find a way to do this, but couldn't find enough
information out there. So sorry if this was already explained
somewhere else. I also hope am asking in the right place.
I have added a custom ribbon tab in an add-in. One of the controls
will consist of 9 small buttons, each button changes the active cell
background to a specific color. This way I expect we'll be saving some
time. My problem is that by changing the color this way (using a VBA
macro) I loose the possibility of undoing the changes. So I was
wondering if it would be possible to simulate the click of the user in
the color filler button that comes in the default Excel ribbon at the
Font group in the Home tab.
After a few hours trying it I could do something similar with:
Application.CommandBars.ExecuteMso ("CellFillColorPicker")
But this solution doesn't allow to undo. Also I couldn't find a way to
change the selected color, so it would be pretty much useless.
I also tried accessing the control doing:
Dim CBR As CommandBar
Set CBR = Application.CommandBars("Fill color")
Dim colControl As CommandBarControl
Set colControl = CBR.Controls(3) 'This three is in order to
access one of the buttons in the bar, in this case, "Standard colors".
But I also tried the rest.
colControl.Execute
But this code's "colControl.execute" doesn't do anything. I guess it's
because I am accessing a CommandBarControl, not a CommandBarButton,
but I didn't find a way to do it. I did though find a way to format
the text bold:
Dim CBR As CommandBar
Set CBR = Application.CommandBars("Formatting")
Dim bold As CommandBarButton
Set bold = CBR.Controls(3)
bold.Execute
And again, this option doesn't allow undoing actions.
So, how should I do it?
Thanks a lot in advance and I hope I explained myself!
Fede