简体   繁体   中英

checkbox rename in excel macro

I would like to create an excel macro, in which I create some chechboxes. When I record the macro, I choose the properties of the chechbox in edit mode, then on the left side i give new position values, size values, name and caption to the chechbox. But the macro itself don't remember, just the size and position values.

It will be in the visual basic code:

ActiveSheet.OLEObjects.Add(ClassType:="Forms.CheckBox.1", Link:=False, _
        DisplayAsIcon:=False, Left:=128.25, Top:=84.75, Width:=108, Height:= _
        21).Select 

When I try to write in the code itself, that Caption:="xyz" , that will be error. How can I handle this?

If you want to do this via your VBA macro. Then the code in this question (not answers) can provide the syntax needed.

Otherwise, the following should work, it's not the cleanest but does the job (hat tip to Google for finding this ):

Sub test()
Dim obj As OLEObject
Set obj = ActiveSheet.OLEObjects.Add(ClassType:="Forms.CheckBox.1")
obj.Name = "checkboxx"
obj.Object.Caption = "CAPTION"
End Sub

Note that you will not be able to run this using the Step Into functionality of VBA (F8).

请看附图1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM