Autorun

  • Thread starter Thread starter EmilH
  • Start date Start date
E

EmilH

Hi.

How can I make my code run as soon as the .xls document is opened?

Thanks in advance.
EmilH.
 
2 ways. One is with and event. See Chip Pearsons site for more info.
http://www.cpearson.com/excel/events.htm

The very simple way is to name the procedure as this:-

Sub Auto_Open() and it will run automatically evary time you open the
workbook.

Sub Auto_Close() runs on closing the workbook.

Regards,

OssieMac
 
Hi E,

Try something like:

'=============>>
Private Sub Workbook_Open()
Call MyMacro
End Sub
'<<=============

This is workbook event code and should be pasted into the workbook's
ThisWorkbook module *not* a standard module or a sheet module:

Right-click the Excel icon on the worksheet
(or the icon to the left of the File menu if your workbook is maximised)
Select 'View Code' from the menu and paste the code.
Alt-F11 to return to Excel.
 
Don't know if this is the best way possible but it's worked for me.

In the VB editor select This Workbook in the VBA Project list, then in the
project window change (General) to Workbook. It should give the following

Private Sub Workbook_Open()

End Sub

now insert location.macro name

Private Sub Workbook_Open()
Module1.mymacro
End Sub
 
Thanks a lot!

Norman Jones said:
Hi E,

Try something like:

'=============>>
Private Sub Workbook_Open()
Call MyMacro
End Sub
'<<=============

This is workbook event code and should be pasted into the workbook's
ThisWorkbook module *not* a standard module or a sheet module:

Right-click the Excel icon on the worksheet
(or the icon to the left of the File menu if your workbook is maximised)
Select 'View Code' from the menu and paste the code.
Alt-F11 to return to Excel.
 
Thanks a lot!

Just a little note: Auto_Open() didn't work but Workbook_Open() did.
 

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