调用子程序和Application.Run之间的区别 [英] Difference between Calling a Sub and Application.Run
问题描述
在我的企业中,我们有一些团队在非常简单的宏上工作.我正在尝试使它们彼此之间以相似的格式相互可读,以便新的连接器可以开始处理数据.
In my business, we have a few teams that work on very simple macros. I'm trying to make them all readable to each other and in somewhat of a similar format, so new joiners can start working on the data.
我提到了简单的宏,因为没有人会使用带有参数的Subs-无论如何大多数都是从Macro Recorder派生的
I mention simple macros, because no one will be using Subs with arguments - most are derived from Macro Recorder anyway
一半的团队使用:
Sub button()
Call sub1()
Call sub2()
Call sub3()
Call sub4()
End Sub
另一半使用
Sub button()
Application.Run("sub1")
Application.Run("sub2")
Application.Run("sub3")
Application.Run("sub4")
End Sub
我了解到,如果您的子程序没有参数,那么Application.Run会有用处-但由于几乎没有任何符号-人们仍然使用Application.Run("")
是有原因的吗?
I understand that if your sub has no arguments, then Application.Run has a use - but being as there's barely any notation on it - is there a reason people still use Application.Run("")
?
能否在Call
的速度和过程中击败它?
Can every use of it be beaten in speed and process by Call
?
推荐答案
如果我尝试运行另一个模块中私有的子级,则使用Application.Run
.如果我有某种模板要在其中向用户隐藏宏,则将其声明为私有,以便他们无法从那里的宏对话框中运行/查看宏.
I use Application.Run
if I’m trying to run a sub that is private in another module. If I have a some kind of template where I want to hide the macros from the users I will declare it as private so they can’t run/see the macro from there macros dialog box.
在module1中,我有
In module1 I have
Private Sub priv()
MsgBox "Private"
End Suv
在module2中,以下内容将为您提供Sub or Function not defined
错误.
In module2 the below will give you a Sub or Function not defined
error.
Sub callPriv()
Call priv()
End Sub
但是在module2中,它将运行并显示消息框
But in module2 this will run and display the message box
Sub callPriv()
Application.Run "priv"
End Sub
使用Application.Run也很有用,如果您要在工作表或thisWorkbook模块中调用一个子项.
It’s also useful to use Application.Run if you are calling a sub in your sheet or thisWorkbook modules.
这篇关于调用子程序和Application.Run之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!