Difference between Calling a Sub and Application.Run

后端 未结 3 1357
广开言路
广开言路 2021-01-21 05:34

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

3条回答
  •  误落风尘
    2021-01-21 06:08

    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
    

提交回复
热议问题