I am using this: How to create a dynamic button in excel
It creates a button and ties a macro to it and works well.
I can run it as a stand alone macro but if I try to call it
Call CreateDynamicButton
Nothing happens, is it possible to call it?
Thanks
Sub CreateDynamicButton()
Dim MyR As Range, MyB As OLEObject
Dim MyR_T As Long, MyR_L As Long
Set MyR = Range("C110") 'just an example - you get that from your own script
MyR_T = MyR.Top 'capture positions
MyR_L = MyR.Left '...
'create button
Set MyB = ActiveSheet.OLEObjects.Add(ClassType:="Forms.CommandButton.1", Link:=False, DisplayAsIcon:=False)
'set main button properties
With MyB
.Name = "MyPrecodedButton" 'important - code must exist ... see below
.Object.Caption = "MyCaption"
.Top = MyR_T
.Left = MyR_L
.Width = 50
.Height = 18
.Placement = xlMoveAndSize
.PrintObject = True 'or false as per your taste
End With
End Sub
If - in advance - you have created following routine within the active sheet
Private Sub MyPrecodedButton_Click()
MsgBox "Co-Cooo!"
End Sub