Difference between Calling a Sub and Application.Run

Badja picture Badja · Mar 20, 2019 · Viewed 12.2k times · Source

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.

I mention simple macros, because no one will be using Subs with arguments - most are derived from Macro Recorder anyway

Half of the teams use:

Sub button()

Call sub1()
Call sub2()
Call sub3()
Call sub4()

End Sub

And the other half use

Sub button()

Application.Run("sub1")
Application.Run("sub2")    
Application.Run("sub3")    
Application.Run("sub4")

End Sub

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("")?

Can every use of it be beaten in speed and process by Call?

Answer

Hasib_Ibradzic picture Hasib_Ibradzic · Mar 20, 2019

You can pass parameters through application.run as well. I use it when I am looping through macros. in your above example instead of having to write this:

Sub button()
  Call sub1()
  Call sub2()
  Call sub3()
  Call sub4()
End Sub

you could write this:

for i = 1 to 4
  application.run("sub" & i)
next i

if the subs took in a str parameter you could do this:

for i = 1 to 4
  application.run("sub" & i, strVariable)
next i