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

Article translations Article translations
Article ID: 265113 - View products that this article applies to.
This article was previously published under Q265113
Expand all | Collapse all

On This Page

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

  1. Save and close all open workbooks.
  2. Open a new workbook, and then start the Visual Basic Editor (press ALT+F11).
  3. Press CTRL+R to switch to the Project Explorer window.
  4. In the Project Explorer window, right-click the ThisWorkbook object, and click View Code on the shortcut menu.
  5. In the module, type the following code:
    Private Sub Workbook_Open()
        Msgbox Date
        Worksheets("Sheet1").Range("A1").Value = Date
    End Sub
    					
  6. Switch to Microsoft Excel and save the workbook.
  7. 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.
  8. Click OK in the message box.
Note, cell A1 on Sheet1 also contains the date as a result of the macro being run.

REFERENCES

For additional information about using auto macros and events, click the following article numbers to view the articles in the Microsoft Knowledge Base:
213624 How to create an Auto_Open macro to show the Data Form dialog box in Excel 2000
213581 XL: Code "behind" worksheet or workbook may not work
213220 XL2000: Summary of Workbook and Worksheet Application Events
211626 XL2000: EnableEvents property does not work in Automation server
For more information about how to use an auto open event, in the Visual Basic Editor, click Microsoft Visual Basic Help on the Help menu, type workbook object events in the Office Assistant or the Answer Wizard, and then click Search to view the topic.

Properties

Article ID: 265113 - Last Review: October 11, 2006 - Revision: 4.2
APPLIES TO
  • Microsoft Excel 2000 Standard Edition
Keywords: 
kbautomation kbdtacode kbhowto kbprogramming KB265113

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com