如何将 VBA 宏绑定到 Excel 中的按钮

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10623704/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 16:10:01  来源:igfitidea点击:

How can I tie a VBA macro to a button in Excel

excelexcel-vbavba

提问by glutz

I have created a macro and a button but I can't see where to edit the button setting to invoke the macro. I'm using Excel 2003.

我创建了一个宏和一个按钮,但我看不到在哪里编辑按钮设置来调用宏。我正在使用 Excel 2003。

回答by Scott Holtzman

If you've used a Form Control. The chance to assign a macro will come up right after you add the button to the sheet. Or, if the button is already on the sheet, you can right-click on it and select Assign Macro.

如果您使用过表单控件。将按钮添加到工作表后,分配宏的机会就会立即出现。或者,如果按钮已经在工作表上,您可以右键单击它并选择分配宏。

If you've used an ActiveXControl, right-click on the button and select View Code. This will open up the VBE with

如果您使用过 ActiveXControl,请右键单击该按钮并选择查看代码。这将打开 VBE

Private Sub myCommandButtonName_Click() 

End Sub

From this sub call your macro like so...

从这个子调用你的宏就像这样......

Private Sub myCommandButtonName_Click() 

Call myMacro

End Sub