I have three modules in my VBA project:
module 1: config_variable
module 2: main_script1
module 3: main_script2
In "config_variable", the codes like this:
Public dir_source1 As String
Public dir_source2 As String
Public dir_source3 As String
Sub global_config()
dir_source1 = range("A2").value
dir_source2 = range("A3").value
dir_source3 = range("A4").value
End Sub
I manage all configurations in this script. And I call this "global_config" Sub for each Sub in module 2 and module 3 to get global variables. Like this:
module 2 - main_script1:
Sub my_sub1()
' call global variables
Call config_variable.global_config
' main codes for my_sub1
.....
End Sub
Sub my_sub2()
' call global variables
Call config_variable.global_config
' main codes for my_sub2
.....
End Sub
module 3 - main_script2:
Sub my_sub3()
' call global variables
Call config_variable.global_config
' main codes for my_sub3
.....
End Sub
The problem is that I need to call the line "Call config_variable.global_config" in the beginning of each Sub.
Is it possible I can just run this line once and every Sub in the same modules can catch the global variables? Like this:
' call global variables on top of each modules
Call config_variable.global_config
Sub my_sub1()
' main codes for my_sub1
.....
End Sub
Sub my_sub2()
' main codes for my_sub2
.....
End Sub