I need a macro to add a checkbox on a worksheet. So far I have
Option Explicit Sub test() ' This macro places a checkbox in the selected cell Dim cb As OLEObject Dim c As MSForms.CheckBox With ActiveCell .RowHeight = 21 Set cb = ActiveSheet.OLEObjects.Add(ClassType:="Forms.CheckBox.1", _ Left:=.Left + 1, Top:=.Top + 1, Width:=1000, Height:=19.5) cb.Name = "chkTest" cb.Object.Caption = "Pretty Cool" cb.Object.AutoSize = True cb.LinkedCell = .Address cb.Object.Value = False .Offset(2, 2).Select End With End Sub
This works, but the Name, chkTest, is associated with the OLEObject, ie it appears in the Name Box when the control is selected in the design mode. What I wanted was the actual control name to be chkTest. That way I could pre-load or dynamically create a click event. I don’t think that this will be necessary, but it has me puzzled. The same code works fine for a ClassType:=”Forms.CommandButton.1″. Then the Name is assigned to the control. Weird! TIA –Sam