run Excel macro on opening

How to run Excel macro on file opening

Here is how to run Excel macro automatically every time you open the file in a few easy steps.

1. When you are in Excel file press Alt + F11 to open VBA window.

2. In the Project section, locate your file and open ThisWorkbook section.

3. You should make subroutine with Workbook_Open event that contains the name of your macro.

Private Sub Workbook_Open()

'Here goes your macro or name of your macro.
NameOfTheMacroOrCode

End Sub

The result looks like this.

If you want to close your workbook automatically when the macro is executed, I recommend adding these lines at the end of the subroutine.

ThisWorkbook.Saved = True

Application.Quit

How to open an Excel file that contains macro (that runs automatically on file opening) without running it.

 

Go to File -> Open (Ctrl + O) and browse to your file.

Open in while holding the Shift key. That will prevent to run a macro automatically.




Posted

in

,

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *