Insert your macro code into a module, start with Sub Auto_Open(). Enter whatever commands you wish to have executed on opening the file and end with End Sub. This will make Excel run macro on open and is the quickest way to run a macro automatically on opening an excel workbook.
Excel Run Macro on Open
To automatically run a macro when you open excel, follow these simple steps;
- Open the VBA editor and create a sub called Auto_Open()
- Enter the VBA code you wish to be executed when your workbook is opened
- Close the Sub (End Sub) and save. Remember to save as a macro enable workbook
This is how you easily make a macro run automatically in Excel when a workbook is opened.
Sub Auto_Open()
'
'MACROS BY EXCELZOOM.COM
'
Msgbox "Hello"
End Sub
Replace “Msgbox “Hello” ” with whatever macro commands you wish to have run whenever your file is opened.
Need help? Use our nifty guide to help figure out how to install and use your macros.
Use the following if you wish to put the macro in your workbook as opposed to in a module. Again replace “Msgbox “Hello”” with your macro command:
Private Sub Workbook_Open()
'
'MACROS BY EXCELZOOM.COM
'
Msgbox "Hello"
End Sub
We hope this will help you in Excel to auto run macros and implement the functionality to run a macro when workbook opens.
Stop a macro automatically running when Opening Excel
Of course, now you know how to create a macro that runs automatically when you open Excel, it is useful to know how to prevent it.
The quickest way way prevent a macro running automatically when you open Excel is to disable macros in the Excel security settings. This will then not run the macro automatically but instead ask you for permission. You can change the settings in a different spreadsheet so you get the desired result when you open the workbook in question.