Difference between Calling a Sub and Application.Run

后端 未结 3 1271
广开言路
广开言路 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:01

    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.

    In module1 I have

    Private Sub priv()
      MsgBox “Private”
    End Suv
    

    In module2 the below will give you a Sub or Function not defined error.

    Sub callPriv()
      Call priv()
    End Sub
    

    But in module2 this will run and display the message box

    Sub callPriv()
      Application.Run “priv”
    End Sub
    

    It’s also useful to use Application.Run if you are calling a sub in your sheet or thisWorkbook modules.

提交回复
热议问题