I have various routines in two different modules. Some clears the report, some populates it, fill the blank spaces with zeroes. I am currently running them using F5. But I want when the user opens the sheet, he gets all populated data without having to run that particular sub routine. Is it possible to run the routines in various modules automatically when the excel is opened?
1 Answer
This is pretty easy. Instead of putting code in the module, you will put it in ThisWorkbook and use the Workbook_Open event. You don't necessarily have to move your code. You can just call the existing macros.
4 Comments
Sunaina
So I need to call my macro inside Workbook_open event in ThisWorkbook.Is that what you mean?
Wyatt Shipman
Yep! That is how you execute code automatically when the workbook opens.
Sunaina
I have two modules with same name sub. So I did module1.func and module2.func, one of them is working correctly, one isn't,am I doing correct?
Wyatt Shipman
It worked for me in a quick test, but is there any issue in renaming one of the subs? My test was
Private Sub Workbook_Open() Call Module1.test Call Module2.test End Sub and each test sub was a Msgbox to say the module name it was in.