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

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
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,216,207
Messages
6,129,508
Members
449,512
Latest member
Wabd

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