I have some code that opens another workbook and runs a macro in the second workbook.
Is there a way that I can use a variable that is set in the first workbook and read it in the code in the second workbook.
Thanks
I have some code that opens another workbook and runs a macro in the second workbook.
Is there a way that I can use a variable that is set in the first workbook and read it in the code in the second workbook.
Thanks
Yes, any variables you set in your macro are available to use until the macro exits, even in secondary workbooks that are opened in the process. You'll have to present a more detailed question and some sample code showing what you want to do.
_________________
Microsoft MVP 2010 - Excel
Visit: Jerry Beaucaire's Excel Files & Macros
If you've been given good help, use theicon below to give reputation feedback, it is appreciated.
Always put your code between code tags. [CODE] your code here [/CODE]
?None of us is as good as all of us? - Ray Kroc
?Actually, I *am* a rocket scientist.? - JB (little ones count!)
Code in workbook1
Code in second workbook![]()
Public data_feed_active As Boolean Sub send_data() data_feed_active = True Workbooks.Open second_work_book, ReadOnly:=True End Sub
What I want to happen is Setup will only be called if the the workbook has not been opened by the first workbook.![]()
Sub Workbook_open() If data_feed_active = True Then Exit Sub Call setup End Sub
However data_feed_active in the second workbook is empty
Before spending any time on your approach, I would simply disable other macros from running while my first macro is doing it's thing:
![]()
Sub send_data() Application.EnableEvents = False 'disable other macros Workbooks.Open second_work_book, ReadOnly:=True 'other code 'other code Application.EnableEvents = True 'turn other macros back on End Sub
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks