我需要在打开电子表格时生成一个按钮并自动分配我之前创建的宏。让我们调用这个宏" edit_colour"。
我知道如何使用" Hello World"执行MsgBox。使用以下,
Private Sub Workbook_Open()
MsgBox "Hello World"
End Sub
答案 0 :(得分:1)
您可以在代码中执行此操作:
Dim w as Worksheet
Dim b As Button
Set w = ActiveSheet
Set b = w.Buttons.Add(5, 5, 80, 18.75) ' left, top, width, height
b.OnAction = "recalculateSomething" ' a sub name in module
b.Characters.Text = "Recalculate Something" ' text on the button
更多信息:How to add a button programmatically in VBA next to some sheet cell data?