VBA Code to add Option Buttons to ActiveX Frame

fm11532

New Member
Joined
Feb 25, 2013
Messages
17
Hi All,

I want to write a VBA code that will place ActiveX Frame directly onto the worksheet and then add 3 Option Buttons from Toolbox into that frame.

I could not find an answer searching through the web... Also when trying to record macro and see the code it did not record placing the buttons from the toolbox or any formatting (color, caption, etc.) via properties...

When formatting the buttons it would be useful if the selected radio button would have different color, bold font, etc.

Would you please provide some examples of code...

Many thanks,
Adam
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
It does not appear anyone knows the code for that.
Why not create the frame and Option buttons and then hide/unhide them.
You can run code to alter the Frame Option buttons format once they are created.
 
Upvote 0
This will add an ActiveX frame to Sheet1 and add 3 option buttons to the frame.
Code:
Dim frm As Object
Dim opt As Object
Dim I As Long

    Set frm = Worksheets("Sheet1").OLEObjects.Add("Forms.Frame.1")
    
    For I = 1 To 3
        Set opt = frm.Object.Controls.Add("Forms.OptionButton.1")
        opt.Caption = "Option" & I
        opt.Top = 5 + (I - 1) * 25
    Next I
 
Upvote 0
Guys ! You are awesome !! This excactly does the trick needed. Short and simple.
I have really been searching through the web for this and to no avail...
Many thanks for all your time and help.
 
Upvote 0

Forum statistics

Threads
1,223,155
Messages
6,170,405
Members
452,325
Latest member
BlahQz

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