The below method uses Auto_Open, which is an old approach for auto run Macro before Workbook_Open Event was implemented.ġ) ALT+11 to enter VBE (Visual Basic Editor)Ĥ) If you already have a Sub Procedure called Macro1, then type Sub Auto_Open() Simply put, open workbook A, hold shift, open workbook B Alternative for Excel Workbook_Open Event using Auto_Open Note that Workbook_Open Event can be skipped by holding SHIFT button, but you need to open that workbook from another workbook. If you want to know more about OnKey Method, click here
For example, the below code assigns hotkey Crtl+Shift+k to Macro1 when Workbook is Opened Private Sub Workbook_Open() Example of Excel Workbook_Open Eventġ) Press ALT+11 to enter VBE (Visual Basic Editor)Ģ) Double click on ThisWorkbook > select Workbook > Select Openģ) Insert your code between Private Sub and End Sub. I cannot pre-format Excel because somehow Access would screw up the pre-formatting. To me, I use Workbook_Open Event to apply formatting after I export data from Access to Excel.
NET Framework but that would require Administration privilege, which could be a problem if you are not an IT administrator at workplace. The reason is that using VB.Net application very likely requires installation of. You may ask why people do this instead of doing a real Visual Basic Application. When user opens the Workbook, a Form pops up and the Excel application (the Excel background) is hidden.
One common use of Workbook_Open Event is that people make application in Excel User Form and they want the Form look like a non-Excel, real Windows application. Event is a Sub Procedure (begin with Private Sub and end with End Sub) and is generated automatically (see in the below section) with a specific name, you can call a Sub Procedure or write your own code within the Event code. For example, you may want to save a workbook automatically when you close a workbook, or you may want a welcome message box to pop up when a workbook is opened. If you perform an Event, say, closing a workbook, your desired code can be triggered. close workbook, open workbook), worksheet has a list of Events (e.g. Each Object has its own list of Events, Workbook has a list of Events (e.g.
For example, activating a worksheet is an Event, closing a workbook is an Event, clicking on a button is an event. Excel predefines some popular actions that you would do on different Objects (worksheet, workbook, button, etc), those actions are called Event.