Assigning a name to ActiveX Option Button in VBA

AskMyDog

New Member
Joined
Nov 13, 2015
Messages
16
Hi all,

This is probably a dumb question, but I can't for the life of me figure out how to assign a name to an ActiveX Option Button when creating it, other than "OptionButton1", "OptionButton2", etc

Just to clarify, I don't want to have to change the name in the properties box for each option button.

Here's the code:

Code:
Sub Add_XCheckboxes()
Dim CLeft, CTop, CHeight, CWidth As Double
Dim lotarget As Excel.ListObject
Dim TableTop, i, TargetDataRowsCount As Long
Dim oCheck As OLEObject
Dim Rec_Sht As Worksheet
Dim Opt_Btn_Count As Long

Application.ScreenUpdating = False

Set Rec_Sht = Sheets("Reconcile Meds Here")
Set lotarget = Sheets("Reconcile Meds Here").ListObjects("Table3")
TableTop = lotarget.Range.Row
Opt_Btn_Count = 4

For Each oCheck In Sheets("Reconcile Meds Here").OLEObjects
        oCheck.Delete
    Next oCheck

TargetDataRowsCount = lotarget.DataBodyRange.Rows.Count

For i = 1 To TargetDataRowsCount
If Not IsEmpty(Cells(TableTop + i, "c")) Then
For j = 1 To Opt_Btn_Count
        CLeft = Cells(TableTop + i, "A").Left + (Cells(TableTop + i, "A").Width * ((j / Opt_Btn_Count) - 0.25))
        CTop = Cells(TableTop + i, "A").Top
        CHeight = Cells(TableTop + i, "A").Height * 0.5
        CWidth = Cells(TableTop + i, "A").Width * 0.5
                With Rec_Sht.OLEObjects.Add(ClassType:="Forms.Optionbutton.1", _
                    Top:=CTop, Left:=CLeft, Height:=CHeight, Width:=CHeigh)
                    .Object.Caption = ""
                    .LinkedCell = "k" & TableTop + i
                    .Object.Value = False
                    .Object.GroupName = "Med rec" & i
               
                End With
        Cells(TableTop + i, "B") = i
        Next j
    End If
Next i
Application.ScreenUpdating = True
End Sub

Any ideas?

Thanks!
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Add
Code:
.Name = "whatever"
inside the With block.
 
Upvote 0
You don't need any parentheses to concatenate strings.
 
Upvote 0

Forum statistics

Threads
1,215,442
Messages
6,124,886
Members
449,194
Latest member
ronnyf85

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