Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Running a Macro in EXCEL, when EXCEL is started!!!!

Status
Not open for further replies.

supanoods

Programmer
Jun 6, 2002
68
GB
Does anybody know how to run an EXCEL Macro as soon as EXCEL is launched?

Cheers

PHASID "If something is hard to do - then it isn't worth doing" - Homer Simpson
 
2 Ways
1: In the WORKBOOK module (double click on the workbook icon in the VBE), use the Workbook_open event
2: In a GENERAL module, create a sub called auto_open()

Either way will work, however, be aware that neither will work if you open the workbook through code. If this is the case, then you will need to "Call" the auto_open or Workbook_open subs from the code that opens the workbook
HTH
Geoff
 
Thank You very much Geoff

PHASID "If something is hard to do - then it isn't worth doing" - Homer Simpson
 
Hi Phasid
If Geoff's answer gave you the solution you were looking for then you might like to give him a star.

However I read your posting as when excel launches, ie the application! As I'm low on things to do I thought I'd post this for the hell of it anyway!!

Create & save a file in this location
C:\Program Files\Microsoft Office\Office\XLStart
and add this code to the workbook module as described above.

Private Sub Workbook_Open()
MsgBox "Hello " & Environ$("username")
Application.Workbooks.Add
ThisWorkbook.Close savechanges:=False
End Sub

This is a totally pointless process unless you call another procedure from this code ie open another workbook etc.

God, I need another job!

;-) If a man says something and there are no women there to hear him, is he still wrong?
"...Three Lions On A Shirt..."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top