0
我使用這個: How to create a dynamic button in excel無法調用VBA的按鈕
它創建了一個按鈕和領帶宏它和行之有效的。
我可以運行它作爲一個獨立的宏,但如果我嘗試調用它
Call CreateDynamicButton
什麼也沒有發生,是有可能打電話了嗎?
感謝
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
如果 - 提前 - 您已經創建以下例行活動表
Private Sub MyPrecodedButton_Click()
MsgBox "Co-Cooo!"
End Sub
這對我的作品。您是否嘗試過調用CreateDynamicButton調用的代碼並查看會發生什麼? –
你打算怎麼稱呼它? '調用CreateDynamicButton'在哪裏? –
感謝您的幫助,問題原來是按鈕宏之前的宏,它運行但未能調用下一個宏,它是宏按鈕。 – xyz