Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call a Subroutine from a different Module in VBA

Tags:

module

vba

call

Is it possible to call a function from one Module to another?

I have the following code:

Sub MAIN()     Call IDLE End Sub 
  • MAIN is located in Module1
  • IDLE is located in Module2 and defined as: Sub IDLE()
like image 319
Nimrod Avatar asked May 10 '10 16:05

Nimrod


People also ask

How do you call a subroutine from a different module?

To call a macro or function that is in the same workbook (it need not be in the same module) just type the name of the macro/function and any arguments it requires on one line of the calling macro. Another way is to prefix the macro/function called with the word Call.

How do I call a macro from a different module?

Just type the word Call then space, then type the name of the macro to be called (run). The example below shows how to call Macro2 from Macro1. It's important to note that the two macros DO NOT run at the same time. Once the Call line is hit, Macro2 will be run completely to the end.


1 Answers

Prefix the call with Module2 (ex. Module2.IDLE). I'm assuming since you asked this that you have IDLE defined multiple times in the project, otherwise this shouldn't be necessary.

like image 190
dcp Avatar answered Oct 13 '22 04:10

dcp