Altering Form Control Buttons

HWL

Active Member
Joined
Dec 1, 2009
Messages
462
I am using the old style form control buttons and I want to be able to do things like change the text and color of the button depending on factors. It is easy enough to reference a controlbutton but how do I reference a form button? formbutton#?
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Is this a button added from the Forms toolbar? If so I don't think that you can change the backcolor. Is it on a worksheet? If so look at the .Caption property.
 
Upvote 0
Is this a button added from the Forms toolbar? If so I don't think that you can change the backcolor. Is it on a worksheet? If so look at the .Caption property.

There are 2 types of controls on Excel 2007, the form controls used in the earlier versions and the newer activex controls. I know how to refer to the activex controls but not the older versions. I inserted a form button into my ducument; default name Button 4. How do I refer to it in a macro?
 
Upvote 0
I am using the old style form control buttons and I want to be able to do things like change the text and color of the button depending on factors. It is easy enough to reference a controlbutton but how do I reference a form button? formbutton#?
I don't think you can change the color, but one way to change the displayed text would be like this (change the sheet and button names as appropriate)...

Code:
Worksheets("Sheet3").Shapes("Button 1").OLEFormat.Object.Caption = "Hello"
 
Upvote 0
I don't think you can change the color, but one way to change the displayed text would be like this (change the sheet and button names as appropriate)...

Code:
Worksheets("Sheet3").Shapes("Button 1").OLEFormat.Object.Caption = "Hello"

Thanks Rick, works perfect. I still think there should be a way to change the color too, I mean if you can change the Caption propert.
 
Upvote 0
Thanks Rick, works perfect. I still think there should be a way to change the color too, I mean if you can change the Caption propert.
You can change the Font color, but I don't believe there is anyway to get to the button's color itself (has something to do with how its drawn onto the sheet I think). Anyway, if changing the color, and making it bold to standout, is sufficient, then...

Code:
With Worksheets("Sheet3").Shapes("Button 1").OLEFormat.Object
  .Caption = "Hello There"
  .Font.ColorIndex = 3
  .Font.Bold = True
End With
 
Upvote 0
You can change the Font color, but I don't believe there is anyway to get to the button's color itself (has something to do with how its drawn onto the sheet I think). Anyway, if changing the color, and making it bold to standout, is sufficient, then...

Code:
With Worksheets("Sheet3").Shapes("Button 1").OLEFormat.Object
  .Caption = "Hello There"
  .Font.ColorIndex = 3
  .Font.Bold = True
End With

Weird, I used this code but then I removed it and yet the font.colorindex keeps changing back to the color I had with the code. Hmmm
 
Upvote 0
Weird, I used this code but then I removed it and yet the font.colorindex keeps changing back to the color I had with the code. Hmmm
Once the color is changed, it is change... the color (and other properties) are not kept "alive" by the code, only changed by it. To put things back the way they were originally, run this code...

Code:
With Worksheets("Sheet3").Shapes("Button 1").OLEFormat.Object
  .Caption = "Button 1"
  .Font.ColorIndex = xlColorIndexAutomatic
  .Font.Bold = False
End With
 
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,756
Members
452,940
Latest member
rootytrip

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