Run macro on opening: worksheet, workbook

Run macro on opening: worksheet, workbook

Microsoft Excel is a spreadsheet application which is included as part of Microsoft office software. It features graphic tools, calculations, pivot tables and macro programming. It has the ability to automatically execute or run an Excel macro code. Macros are the set of commands used to create, record and save repetitive tasks.

Autorun a macro:

If you want to autorun a macro when opening a worksheet then you need to type your macro name in the Worksheet_Activate() event and this code will run a macro when opening your Excel spreadsheet. Similarly Worksheet_Deactivate() event code will run your macro when closing a sheet.

Procedure

Right click the sheet tab and paste these two event codes:

Private Sub Worksheet_Activate()    
macro name    
End Sub
Private Sub Worksheet_Deactivate()    
macro name     
End Sub
Anymore excel questions? check out our forum!
Around the same subject

Excel