Microsoft KB Archive/265113

= How to make a macro that automatically starts when you open a workbook in Excel 2000 =

Article ID: 265113

Article Last Modified on 10/11/2006

-

APPLIES TO


 * Microsoft Excel 2000 Standard Edition

-



This article was previously published under Q265113



SUMMARY
One way to automatically run a macro when you open a workbook is to use the Workbook_Open event in Microsoft Excel. Workbook_Open is a built-in workbook event that runs its macro code each time you manually open the workbook.

The following example uses the Workbook_Open event to run a macro when you open the workbook.



MORE INFORMATION
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.

Example
 Save and close all open workbooks. Open a new workbook, and then start the Visual Basic Editor (press ALT+F11). Press CTRL+R to switch to the Project Explorer window. In the Project Explorer window, right-click the ThisWorkbook object, and click View Code on the shortcut menu.  In the module, type the following code: Private Sub Workbook_Open Msgbox Date Worksheets(&quot;Sheet1&quot;).Range(&quot;A1&quot;).Value = Date End Sub  Switch to Microsoft Excel and save the workbook. Close and reopen the workbook.

When you open the file again, Excel runs the Workbook_Open macro, which displays today's date in a message box.</li> Click OK in the message box.</li></ol>

Note, cell A1 on Sheet1 also contains the date as a result of the macro being run.

<div class="references_section">