MrExcel Publishing
Your One Stop for Excel Tips & Solutions

Auto Execute On Focus

Posted by Michele on May 29, 2001 1:38 AM

It is possible to automatically execute VB code upon opening an Excel file. Is it possible to do the same every time the opened file gets the focus and if so, how? I have an Excel file which opens a Word document. When the user closes the Word document the Excel file is visible again but I can't get it to automatically execute some houskeeping code which is needed to get things back in order.

Posted by Dave Hawley on May 29, 2001 1:56 AM

Hi Michele

Right click on the sheet picture, top left next to file and select "View Code". If you are using Excel 97 it will default to:
Private Sub Workbook_Open()

End Sub

if using Excel 2000, select "Workbook" from the "Object" box, top left of Module. In both versions all Events for the Workbook Object are in the "Procedure" box, top right of Module.

You are probably after the:

Private Sub Workbook_Activate()

End Sub


OzGrid Business Applications

Posted by Michele on May 29, 2001 3:07 AM

Many thanks Dave. It's so easy when you know where the stones are!