Run a macro when a workbook is opened

  • Thread starter Thread starter Mervyn Thomas
  • Start date Start date
M

Mervyn Thomas

I know its there somewhere but I cannot find help on how to run a macro
which runs automatically when a workbook is opened and again how to run a
macro when a workbook is closed.
I can't figure out how to run open and close events!
Can anyone get me started?
 
Hi,


Workbook_Open is an "event procedure" and needs to go in
the module of the ThisWorkbook object.

Alt+F11 to the VB editor
In the project explorer window double-click the
ThisWorkbook entry under Microsoft Excel Objects.
In the code window which should now be showing you the
module for ThisWorkbook:
- select Workbook from the left hand dropdown at the top
of the window
- select Open from the right hand dropdown [may have
happened automatically]
- type your code between the lines
Private Sub Workbook_Open()
and
End Sub
which will have been generated automatically.

Regards,

Jan Karel Pieterse
Excel TA/MVP
 
Merevyn,

Name the macros Auto_Open and Auto_Close.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com (e-mail address removed)
 
Back
Top