I have an excel file with 2 buttons which access two different modules. Can we access a variable of a module in another module after running the program which calls that module?
My modules look like this

1st module..
Public Sub Directory_Path()
Dim Directory As String
Directory = InputBox("Enter the Directory path that contains folders ""This Quarter"",""Last Quarter"",""Second_Last_Quarter"".")
If Right(Directory, 1) = "\" Then
Directory = Left(Directory, Len(Directory) - 1)
End If
End Sub
I called the the first module in 2nd module using Public Sub Directory_Path() . I want Directory variable in first module to be used as a variable in 2nd module...
In 1st module - declare Directory as Public at top of module outside of any Sub/Function. It's now available to every module in this project:
Public Directory As String
Sub Directory_Path()
Directory = InputBox("Enter the Directory path that contains folders ""This Quarter"",""Last Quarter"",""Second_Last_Quarter"".")
If Right(Directory, 1) = "\" Then
Directory = Left(Directory, Len(Directory) - 1)
End If
End Sub
In 2nd module, just use the name Directory wherever you need it. Example:
MsgBox "The directory path is " & Directory
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With