VBA to change CommandButton colour

LORDMARKS

New Member
Joined
Jun 5, 2014
Messages
39
Hi all

I am looking for a way to change the colour of a command button, based on a value. I have some code running on load up to check certain values and carry out functions accordingly. One of the checks prompts the user to check a certain sheet if the criteria is met, but I would also like it to highlight the Command button (used to navigate to sheet) RED until the issue has been resolved.

I have found code to run on click, but it won't work as part of the 'on load' code ?

Has anyone got a simple bit of code to change colours from any Sub?

Thanks in advance as always
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Maybe Something Like this for an ActiveX Command Button:

Code:
[COLOR=#0000ff]Sub [/COLOR]ChangeCmdBtnColor()

[COLOR=#0000ff]     If [/COLOR]Range("A1").Value = "Test" [COLOR=#0000ff]Then[/COLOR]
          ActiveSheet.OLEObjects("CommandButton1").Object.BackColor = &HFF& [COLOR=#008000]'Red[/COLOR]
[COLOR=#0000ff]     End If[/COLOR]

[COLOR=#0000ff]End Sub[/COLOR]

You could probaby list your CommandButton Names as variables to get the results you want. i.e. :
Code:
ActiveSheet.OLEObjects([B][COLOR=#ff0000]YourVariableName[/COLOR][/B]).Object.BackColor = &HFF& [COLOR=#008000]'Red[/COLOR]
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,715
Members
448,985
Latest member
chocbudda

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