How do you run/call a module in another module in VBA excel?
101,770
Answer:
Sub main_TRY1()
Call Module2.Formating
Call Module3.Data
End Sub
Author by
Nur Atiqah Hassan
Updated on November 05, 2021Comments
-
Nur Atiqah Hassan over 2 years
Okay so i have 3 modules. My first module is "main" that is the module that i need to call the other module. What i mean is that when i run main, i want it to
call/run
the other 2 module. Currently when i press F5, it doesn't do this. How do i do this?My current code looks like this:
Sub main_TRY() Call Module2 Call Module3 End Sub
All help is greatly appreciated. Thank you.
-
Admin almost 9 yearsThat is only necessary if Formatting and Data were declared as Private Sub. A Public Sub is the default so if they were declared as
Public Sub Formating(...)
orSub Formating(...)
thenCall Formating(...)
or simplyFormating(...)
is appropriate. The(...)
is not needed unless you are throwing parameters into the sub. -
Arthur Hebert-Ryan almost 7 yearsThanks @Jeeped. After I removed Private from my function definitions, I was able to call them from another module. And I did not need to include the module name in the call to my (now public) function.