Hello this have been giving me a headache for a while.
I want to simply be able to remove existing buttons and add new ones. I already have ready made functions xbutton_click() and ybutton_click(). I tried adding buttons like this:
Set btn= ActiveSheet.Buttons.Add(Range("B3").Left, Range("B3").Top, Range("B3").Width, Range("B3").Height)
With openForm
.OnAction = "new_Click"
.Caption = "new"
.Name = "newButton"
End With
but those seem to only work with macros which is not what I want. I realized that when I manually add a button, I add the active X control button. I want that. It has a name property, which can be changed, and its function is basically name_click(), perfect!
Now when it comes to adding them its a headache. I have surfed the internet but it is full of outdated solutions (I am using 2013). I could only add new command buttons, but couldn't change their caption, name, nothing.
this is the code for adding a "command button" (not "button"):
Set objBtn = ws.OLEObjects.Add(ClassType:="Forms.CommandButton.1", link:=False, _
displayasicon:=False, Left:=celLeft, Top:=celTop, Width:=celWidth, Height:=celHeight)
Adding the ActiveX Command Button works, but I cannot change its properties like "Caption". Can someone please guide me through this maze?
Edit
objBtn.Name = "newName" works. But objBtn.Caption = "newCaption" gives an error 438.

.OnAction. Yet, ActiveX controls do not come with this option. The macro (when clicking onCommandButton1for example) must be namedCommandButton1_Clickand must reside on the sheet where the ActiveX command button resides. So, what you are essentially asking for is a macro (VBA code) to change the VBA code residing on a particular sheet.objBtn.Name = "newButton"to set the name of your ActiveX Command Button after it is created. This has worked for me in 2010 and 2016 without issueobjBtn.Object.Caption = ""You can find this by adding a 'watch' on your command button and looking at the hierarchy of properties