vba 如何从另一个工作表调用宏。?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12668452/
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 17:54:36  来源:igfitidea点击:

How to call a macro from another worksheet.?

excelexcel-vbavba

提问by user1710970

I have assigned a macro to a button in worksheet 2. I have created a new button in a new worksheet and now i want the same macro to run or call from worksheet 4.

我已将宏分配给工作表 2 中的按钮。我在新工作表中创建了一个新按钮,现在我希望从工作表 4 运行或调用相同的宏。

回答by whytheq

...hmm....

...唔....

Put your code in a module:

把你的代码放在一个模块中:

enter image description here

在此处输入图片说明

You can then call it from anywhere. If you were to add an ActiveX control to a sheet then you could just double click the button in design mode and amend the code to the following and it should work:

然后您可以从任何地方调用它。如果要将 ActiveX 控件添加到工作表,则只需在设计模式下双击该按钮并将代码修改为以下内容,它应该可以工作:

Private Sub CommandButton1_Click()
  Call CallMeFromAnyWorkSheet
End Sub