Search code examples
vbaexcelactivex

How to select an ActiveX Option/Radio Buttons in Form Controls


I have a Form Control with ActiveX Radio/Option Buttons in it. The Form Control name is Side and contains Option/Radio Buttons with names xOption, oOption, and randomSide. How would I be able to create a Macro that would allow me to set the radio buttons to a certain value upon opening the workBook. Recording a Macro of me clicking options results in a blank Macro. I've Already tried:

ActiveSheet.Shapes.Range(Array("Side")).Select
ActiveSheet.Shapes.Range("xOption").OLEFormat.Object.Value = 1

But this gives me error 1004 and other codes give me error 91. I'm really new to VBA so if I look stupid you know why.


Solution

  • Try something like this, using Worksheets instead of ActiveSheet:

    Private Sub Workbook_Open() 
        Worksheets("your sheet name here").OLEObjects("xOption").Object.Value = 1 
    End Sub
    

    As you want it to be selected after opening the sheet. Place this on ThisWorkbook.