Auto_Run Macro

I

imran_subzwari

Helo,
Can any body tell me how can a macro be executed automatically when
ever i open a workbook.
Thanks in advance
 
N

Neily

Hi,

Put whatever code you wish to run inside a Sub called
Auto_Open and it will be run whenever the workbook is
opened.

eg.

Sub Auto_Open

MsgBox("This message will appear as soon as this
workbook has opened!!")

End Sub
 
T

Tom Ogilvy

Just some added info:
Note that Workbook_Open is a workbook level event and should be placed in
the ThisWorkbook module of the workbook rather than a sheet module or a
general module.

Go into the VBE (alt+F11) and look in the project explorer (Ctrl+R if it
isn't visible). Find your workbook in the "tree" and look for the
ThisWorkbook entry under that. Double click on ThisWorkbook and the
thisworkbook module will open. In the left dropdown at the top select
Workbook and in the right dropdown, select open. It will put in the
skeleton declaration for the Open Event

Private Sub Workbook_Open()

End Sub

put your code in that declaration or call it from that declaration.
 

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

Top