View Full Version : Solved: Auto_open macro

11-20-2005, 03:21 PM
I want to run a macro each time outlook opens.


11-21-2005, 02:44 AM
In the VBE, select ThisOutlookSession in the project explorer and in the Object box (the left combo box above the code window, choose Application. The right combo cox now has a list of all the application events. Choose Startup and insert your code into the Application_Startup routine.
Now when you save, you will be saving "vbaProject.OTM" - this is the default vba project for Outlook which is loaded each time Outlook is started.

ThisOutlookSession is a bit of a nisnomer in that respect - it really means "TheDefaultOutlookSession"

11-21-2005, 03:19 AM
I can't make it run when outlook starts.
I attach the code.

11-21-2005, 06:37 AM
I don't see a problem with the code (except a few extra VB lines)
I tested it with the following steps:
Pasted the code from the cls file (opened with notepad) into the ThisOutlookSession module
Delete/comment out the unwanted lines at the start'VERSION 1.0 CLASS
' MultiUse = -1 'True
'Attribute VB_Name = "ThisOutlookSession"
'Attribute VB_GlobalNameSpace = False
'Attribute VB_Creatable = False
'Attribute VB_PredeclaredId = True
'Attribute VB_Exposed = True
Changed the "SubFolder" definition to point to a folder that existed in my setup
Created a folder C:\Email Attachments
Ran the code - successfully saved the attachment
Quit Outlook, saving vbaProject.OTM
Deleted the test file saved
Re-opened Outlook - the code fired - the attachment was saved

Is the code not firing at startup, or not doing what you expect?

This is similar to a KB article (http://vbaexpress.com/kb/getarticle.php?kb_id=522) I did, except in that, the application startup code set up a "wachted" folder that saved (and printed) any Excel mails that had Excel attachments when they arrived. You might want to take a look at that too.

11-21-2005, 07:00 AM
The code did not start when I restart outlook. Maybe missing some settings? I also change the security level to low. Thanks

11-21-2005, 08:13 AM
You can also check the Task Manager to make sure Outlook.exe isn't running in hiding, as it would prevent the startup event from being triggered. Or simply reboot the computer.

11-21-2005, 10:01 AM
I test it in another pc in the same network and it's ok!
So something wrong with outlook installation, or something else.

11-22-2005, 06:58 AM
I want to make it work in another mailbox (shared). How can I make it to be my default inbox?

02-03-2008, 11:04 PM
We have the same requirement !!!

We have coded an outlook VBA which checks the incoming mails and if it matches with particular sendername & subject name we process the mail and generating a document automatically.
In our outlook we have two mailboxes one is Personal mailbox and another one is shared mailbox. We are able to use Application_NewMail in "ThisOutlookSession" to fire the VBA whenever mail comes to "Personal Mailbox" .
This code not fired when new mail comes into "Shared Mailbox" .

Is that possible?
Can anyone help ?

Thanks in Advance...