0
Thanks

A few words of thanks would be greatly appreciated.

Excel - Run a macro when opening a sheet

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. Excel, 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. 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.


Issue


I need to run a macro automatically when I open an Excel sheet and also to run a macro when I close the sheet. Can anyone help me with this?

Solution

  • 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

Note that


Thanks to venkat1926 for this tip on the forum.
0
Thanks

A few words of thanks would be greatly appreciated.

Ask a question
Jean-François Pillou

CCM is a leading international tech website. Our content is written in collaboration with IT experts, under the direction of Jeff Pillou, founder of CCM.net. CCM reaches more than 50 million unique visitors per month and is available in 11 languages.

Learn more about the CCM team

Published by . Latest update on by aakai1056.

This document, titled "Excel - Run a macro when opening a sheet," is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (https://ccm.net/).

0 Comments