VBA在OnAction中包含子例程的参数
我有一些代码可以在Excel VBA中构建菜单,如下所示:VBA在OnAction中包含子例程的参数,vba,excel,Vba,Excel,我有一些代码可以在Excel VBA中构建菜单,如下所示: For Each Thing In Array("Foo", "Bar", "Baz") With .Controls.Add(Type:=msoControlButton) .Caption = "Run with " & Thing .FaceId = 2934 .OnAction = "'" & ThisWorkbook.Name & "'!"
For Each Thing In Array("Foo", "Bar", "Baz")
With .Controls.Add(Type:=msoControlButton)
.Caption = "Run with " & Thing
.FaceId = 2934
.OnAction = "'" & ThisWorkbook.Name & "'!" & "RunWith" & Thing
End With
Next Thing
Sub RunWithFoo()
RunWith "Foo"
End Sub
Sub RunWithBar()
RunWith "Bar"
End Sub
Sub RunWithBaz()
RunWith "Baz"
End Sub
Sub RunWith(Thing) ...etc
有没有一种方法可以不经过RunWithFoo
etc助手方法直接调用RunWith?下面是一个示例
Sub Sample()
Dim Thing
Thing = "Sid"
Application.OnKey "^{s}", "'RunWith""" & Thing & """'"
End Sub
Sub RunWith(Thing)
MsgBox Thing
End Sub