我有一些代码可以在Excel VBA中构造菜单,如下所示:
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
有没有一种方法可以直接调用RunWith,而无需通过RunWithFoo
etc助手方法?
这是一个例子
Sub Sample()
Dim Thing
Thing = "Sid"
Application.OnKey "^{s}", "'RunWith""" & Thing & """'"
End Sub
Sub RunWith(Thing)
MsgBox Thing
End Sub
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句