automatic Macro at start

  • Thread starter Thread starter Sophie
  • Start date Start date
S

Sophie

Is it possible to have a macro execute itself
automatically when you open the workbook it is associated
to in Excel 2002?
 
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
 
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top