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
Share:
101,770
Nur Atiqah Hassan
Author by

Nur Atiqah Hassan

Updated on November 05, 2021

Comments

  • Nur Atiqah Hassan
    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
    Admin almost 9 years
    That 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(...) or Sub Formating(...) then Call Formating(...) or simply Formating(...) is appropriate. The (...) is not needed unless you are throwing parameters into the sub.
  • Arthur Hebert-Ryan
    Arthur Hebert-Ryan almost 7 years
    Thanks @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.