How rename a checkbox with VBA

2019-09-06 20:45发布

I want to change the caption and the method's name of some Checkbox that I'm doing in a new sheet. The code that I have so far is:

Sheets("Sheet1").OLEObjects.Add "Forms.CheckBox.1", _
Left:=Cells(fil_1, col_1).Left - 11.25, _
Top:=Cells(fil_1, col_1).Top, _
Width:=Range("A1").Width, Height:=Range("A1").Height
'Caption:=""

1条回答
放我归山
2楼-- · 2019-09-06 21:24

Like this:

Set ole = ActiveSheet.OLEObjects
ole(1).Name = "New Name"
ole(1).Object.Caption = "New Caption"

Or to make it easier, simply modifying your example:

set newCheckbox = Sheets("Sheet1").OLEObjects.Add "Forms.CheckBox.1", _
Left:=Cells(fil_1, col_1).Left - 11.25, _
Top:=Cells(fil_1, col_1).Top, _
Width:=Range("A1").Width, Height:=Range("A1").Height
'Change name and caption
newCheckbox .Name = "New Name"
newCheckbox .Object.Caption = "New Caption"
查看更多
登录 后发表回答