Excel – Automatically Run A Macro

Auto run macro excel… Do you want to run an excel macros automatically when the file is open or close?

Microsoft Excel provide us the opportunity to run a macro automatically every time we open or close the excel workbook file, using the event Workbook_Open and Workbook_BeforeClose.

In the Microsoft Visual Basic Editor page, in the ThisWorkbook module, we simply create two new sub procedure called Workbook_Open and Workbook_BeforeClose. In both sub procedure, we call the method that we want to run automatically when the workbook is open or closed.

Private Sub Workbook_Open ()
	 
	    Call onFileOpenMacro
	 
End Sub

Private Sub Workbook_BeforeClose (Cancel As Boolean)
	 
	    Call onFileCloseMacro
	 
End Sub

In this example, when the workbook is opened, we will automatically run macros called onFileOpenMacro, we also automatically run macros called onFileCloseMacro just before the excel workbook is closed.

SOURCE

LINK

LANGUAGE
ENGLISH