Example
A simple example will be demonstrated, with the following tree in VBA:
So,assumethatalltheprogrammingisinthesameWorkbook.
Inmodule1therewillbeSubexecutar()
Inmodule2thefollowingcode:
Subteste1()MsgBox"1"
End Sub
And in module 3:
Sub teste2(text As String)
MsgBox text
End Sub
Private Sub teste3()
MsgBox "3"
End Sub
Explanation
When running with the following code:
Sub executar()
Call teste1 'Não é necessário o Call, somente o VBA ainda utiliza esta sintaxe
teste2 "2"
teste3
End Sub
An error will occur in teste3
, since it is a Private Sub
of module3.
But when running with:
Sub executar()
Call teste1 'Não é necessário o Call, somente o VBA ainda utiliza esta sintaxe
teste2 "2"
End Sub
The code will work correctly, because even though test1 () and test2 () are in other modules, they are declared as Public.
To run a Private Sub from another module, use:
Sub executar()
teste1
teste2 ("2")
Application.Run "Módulo3.teste3"
End Sub
So it is necessary to call Subs in another Sub to accomplish this.
For more advanced code, refer to this reference: Programming The VBA Editor . In that you can perform actions within the VBA Project, being able to list the Subs of the modules and give run.