Use one workbooks variables from another?
Is it possible, while using workbookA, to call a macro from workbookB and access the variables from workbookB's macro?
workbookB has a macro named newSession()
I run it from workbookA with:
Application.Run "workbookB!Module1.newSession"
newSession populates a Global variable session1
is it possible to access the variable session1 from the code in workbookA?
Re: Use one workbooks variables from another?
Define the variable as Public (instead of Dim). eg Workbook B would need a line like :-
Code:
Public MyVariable As String
Re: Use one workbooks variables from another?
How would you refer to the variable from the other workbook?
If session1 is a string, while the project is running I can go to the immediate window and type 'print session1' and it will print fine. If I activate any of the sheets in the other project and attempt the same print command, it returns a null value. Switch back the the original project and it retains its original value.
This happens with the variable declared both public and global (which I guess is the same in vba)