Making an ActiveX Button with a sub binded

nicolasnam

New Member
Joined
Feb 21, 2018
Messages
3
Hi,
I'm looking for someway to implement the 'OnAction' command which only exists for the normal form control button into the following ActiveX Command Button.

Dim qb As Object 'Quit game button
Dim qbr As Range
Set qbr = ActiveSheet.Range("K14:K15")
Set qb = ActiveSheet.OLEObjects.Add(ClassType:="Forms.CommandButton.1", Left:=qbr.Left, Top:=qbr.Top, Width:=qbr.Width, Height:=qbr.Height)
With qb
.Object.Caption = "Quit"
.Object.BackColor = RGB(244, 176, 132)
.OnAction = "end_game"
End With

P.S. This is my first day using VBA.
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
ActiveX buttons don't have an OnAction property, they have their own events, eg CommandButton1_Click etc.

Is there a reason you are using ActiveX buttons over Forms buttons?
 
Upvote 0
I need to make a colored button and I read that only ActiveX buttons can be customized in that way. It would be delightful if you could go into more detail regarding the 'CommandButton1_Click' or any other commands that would assist me.
 
Upvote 0

Forum statistics

Threads
1,215,856
Messages
6,127,365
Members
449,381
Latest member
Aircuart

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