How to run VBA macro when open or close workbook?
In many cases we may use the VBA code to achieve the operations which Excel built-in functions not support. But have you ever tried to run the VBA macro in each time of opening or closing the workbook. In this article, I will tell you how to run the VBA code while opening or closing the workbook every time.
Tabbed browsing & editing multiple Excel workbooks/Word documents as Firefox, Chrome, Internet Explore 10!
You may be familiar to view multiple webpages in Firefox/Chrome/IE, and switch between them by clicking corresponding tabs easily. Here, Office Tab supports similar processing, which allow you to browse multiple Excel workbooks or Word documents in one Excel window or Word window, and easily switch between them by clicking their tabs. Click for free 45-day trial of Office Tab!
1. Enable the workbook, press Alt + F11 keys to open the Microsoft Visual Basic for Applications window.
2. Double click ThisWorkbook in Project – VBAProject pane to open the ThisWorkbook (Code) window.
2. In the code window, select Workbook from the left drop down list. Notice that, in default, the Open will be displayed in right drop down list, if not, change it to Open.
3. Then copy your own code without the first and last line and paste between Private Sub Workbook_Open() and End Sub as below screenshot shown.
4. Then click Save button to save the code, in the popping reminder dialog, click No.
5 Then a Save As dialog pops out, save the file as Excel Macro-Enabled Workbook and select a folder to place the file.
6. Click Save button. Now the code will run while the workbook is open.
If you want to run the code while closing workbook each time, select Deactiviate from the right drop down list in the Code window, and copy the code you will run and paste between Private Sub Workbook_Deactivate() and End Sub.
Easily Combine multiple sheets/Workbook into one Single sheet or Workbook
|To combinne multiples sheets or workbooks into one sheet or workbook may be edious in Excel, but with the Combine function in Kutools for Excel, you can combine merge dozens of sheets/workbooks into one sheet or workbook, also, you can consolidate the sheets into one by several clicks only. Click for 60 days free trial!|
|Kutools for Excel: with more than 200 handy Excel add-ins, free to try with no limitation in 60 days.|