how to assign a name to checkbox at creation time.

Gringoire

Board Regular
Joined
Nov 18, 2016
Messages
71
Office Version
  1. 365
Platform
  1. Windows
Hi guys,
I need to create by code some checkboxs in a worksheet but I'm not able to assign them a name:
VBA Code:
    ActiveSheet.OLEObjects.Add ClassType:="Forms.CheckBox.1", _
    Link:=True, DisplayAsIcon:=False, _
    Left:=Range("d8").Left, Top:=Range("d8").Top, Width:=Range("d8").Width, Height:=Range("d8").Height, Name:="Pippo"
It seems that Argument "Name" does not exist.
where am I doing wrong?

thanks.
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Try:

Code:
ActiveSheet.OLEObjects.Add(ClassType:="Forms.CheckBox.1", _
    Link:=True, DisplayAsIcon:=False, _
    Left:=Range("d8").Left, Top:=Range("d8").Top, Width:=Range("d8").Width, Height:=Range("d8").Height).Name = "Pippo"

though I would recommend you use Form controls rather than ActiveX if you can.
 
Upvote 0
Solution
...though I would recommend you use Form controls rather than ActiveX if you can.

thanks. With form controls is much easier:
VBA Code:
Sub AddCheckBoxes()

    Dim cb As CheckBox
    Dim wks As Worksheet

    Set wks = Sheets("LOAD")
    Set cb = wks.CheckBoxes.Add(cel.Left, cel.Top, 30, 6)

        With cb
            .Caption = "Pippo"
            .Name = "Pippo"
            .Value = xlOff
            .OnAction = "mymacro"
        End With

End Sub
 
Upvote 0
Yep, and more stable too.
 
Upvote 0

Forum statistics

Threads
1,215,054
Messages
6,122,897
Members
449,097
Latest member
dbomb1414

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