ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Run a macro when a workbook is opened (https://www.excelbanter.com/excel-programming/272647-run-macro-when-workbook-opened.html)

Mervyn Thomas[_3_]

Run a macro when a workbook is opened
 
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?




Jan Karel Pieterse

Run a macro when a workbook is opened
 
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

-----Original Message-----
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?



.


Chip Pearson

Run a macro when a workbook is opened
 
Merevyn,

Name the macros Auto_Open and Auto_Close.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"Mervyn Thomas" wrote in message
...
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?







All times are GMT +1. The time now is 05:38 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com