Forum Discussion
Automatically run a macro when opening a workbook
- Sep 13, 2022
connderosa you need to open the VBA window (ALT-F11) and then in the project explorer (CTRL-R if it isn't already open) you expand the 'microsoft excel objects' folder and double click the "ThisWorkbook".
You should then get a blank page as shown in the image below and click the left drop down and select 'Workbook'. This should automatically insert a
Private Sub Workbook_Open()
End Sub
Then put the code you want to run between those 2 lines
and in the end make sure you save it as a .xlsm or .xlsb file type
hmmm... I should have opened that link first as it says the same thing but better. lol.
so maybe you need to explain better what your question/need is
connderosa you need to open the VBA window (ALT-F11) and then in the project explorer (CTRL-R if it isn't already open) you expand the 'microsoft excel objects' folder and double click the "ThisWorkbook".
You should then get a blank page as shown in the image below and click the left drop down and select 'Workbook'. This should automatically insert a
Private Sub Workbook_Open()
End Sub
Then put the code you want to run between those 2 lines
and in the end make sure you save it as a .xlsm or .xlsb file type
hmmm... I should have opened that link first as it says the same thing but better. lol.
so maybe you need to explain better what your question/need is
- mtarlerOct 28, 2022Silver Contributorno the code doesn't have to all be in that module. why is the other a Private Sub instead of a Public Sub? it is hard to see what exactly you are doing, you should share the workbook or a sample without any private info. If you can't post the workbook then you can host it in onedrive or the like and share a link. Also you should post this as a new question as this isn't directly related to the above post and you could get additional helpers chime in
- TSawyer1226Oct 28, 2022Copper ContributorOk.