automatic Macro at start

S

Sophie

Is it possible to have a macro execute itself
automatically when you open the workbook it is associated
to in Excel 2002?
 
C

Chip Pearson

Sophie,

Name the macro Auto_Open, or put the following in the ThisWorkbook code
module:

Private Sub Workbook_Open()
'
' your code here
'
End Sub


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

Alan

Yes,
It will give the Macro warning which has to be there to alert the
user that there could be malicious code in the file. You can use the
Workbook_Open or WorkBook_Activate events to run your code.

An example, Copy and paste this into a new workbook,

Highlight and copy the code below,
Open a new workbook,
Hit Alt and F11,
Double click ThisWorkboook on the left of the screen,
Paste.

Private Sub Workbook_Activate()
Sheet1.Range("A1").Value = "An Example"
End Sub

Save the file, close and re-open it,
Look at Sheet1, A1

Regards,
Alan.
 
Top