在 vba 中使用按钮调用子函数

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

calling a sub function with a button in vba

excelvbaexcel-vba

提问by Mikz

I have 10 Sub function macros in "This workbook". Instead of running each macros, everytime i wanted an userform with button, and when I click , it should execute all the Sub function in "This workbook".

我在“本工作簿”中有 10 个子函数宏。而不是运行每个宏,每次我想要一个带有按钮的用户表单,当我点击时,它应该执行“这个工作簿”中的所有子功能。

I created another function like calling, and I used the following code,

我创建了另一个函数,比如调用,我使用了以下代码,

Sub calling()


Call lookup
Call RangeTest
 Call datecompare
Call AutoPivot
Call Autochart
 Call pivot
Call chart
Call pivot1
End Sub

so, whenever I go for macros, I select Sub calling() and it executes the 10 Sub functions. I would like to have it through a button click. Could anyone suggest how I can do this ?

因此,每当我使用宏时,我都会选择 Sub calls() 并执行 10 个 Sub 函数。我想通过单击按钮来获得它。谁能建议我如何做到这一点?

回答by MisterBic

You should simply add a button from the developper ribbon and assign it to calling(). However, make sure all your macros are in the same module or else you'll have to specify it. If you still get an error it would be interesting to see on what line the error is coming from.

您应该简单地从开发人员功能区添加一个按钮并将其分配给调用()。但是,请确保您的所有宏都在同一个模块中,否则您必须指定它。如果您仍然收到错误,那么查看错误来自哪一行会很有趣。

Thank you

谢谢