How to set ActiveX caption & color via VBA ???

Aid2Kids

New Member
Joined
Oct 27, 2017
Messages
9
Hello everyone,

I've been using Excel/VBA for years now, but I've only just now starting to use an ActiveX control. Here's what I'm trying to do...

1) Create an ActiveX command button (on a sheet) via VBA,
2) Set the button's name,
3) Set the button's caption,
4) Set the button's background color.

Here's as far as I gotten...

Dim objButton As Object
Set objButton = Worksheets("TS_Dir").OLEObjects.Add(ClassType:="Forms.CommandButton.1", Link:=False, DisplayAsIcon:=False, Left:=350, Top:=120, Width:=50, Height:=20)

The above works, but I've been able to set the caption and color. I was expecting to use something along the lines of ...

object.Property = ...

...but this isn't working. Would someone please be so kind as to point me in a better direction?


Thanks!
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Try:
Code:
Set objButton = Worksheets("TS_Dir").OLEObjects.Add(ClassType:="Forms.CommandButton.1", Link:=False, DisplayAsIcon:=False, Left:=350, Top:=120, Width:=50, Height:=20)
objButton.Object.Caption = "My Button"
objButton.Object.Font.Bold = True
objButton.Object.BackColor = &HFFFF&
objButton.Object.ForeColor = &HFF0000
 
Upvote 0
V_Malkoti

THANK YOU for your prompt and most helpful response! Your code statements work beautifully.


Take care
 
Upvote 0

Forum statistics

Threads
1,223,952
Messages
6,175,596
Members
452,657
Latest member
giadungthienduyen

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