Consulting

Results 1 to 9 of 9

Thread: Solved: Auto_open macro

  1. #1

    Solved: Auto_open macro

    I want to run a macro each time outlook opens.


    Thanks.

  2. #2
    VBAX Master Killian's Avatar
    Joined
    Nov 2004
    Location
    London
    Posts
    1,132
    Location
    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"
    K :-)

  3. #3
    I can't make it run when outlook starts.
    I attach the code.
    Thanks.

  4. #4
    VBAX Master Killian's Avatar
    Joined
    Nov 2004
    Location
    London
    Posts
    1,132
    Location
    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[VBA]'VERSION 1.0 CLASS
    'BEGIN
    ' MultiUse = -1 'True
    'End
    'Attribute VB_Name = "ThisOutlookSession"
    'Attribute VB_GlobalNameSpace = False
    'Attribute VB_Creatable = False
    'Attribute VB_PredeclaredId = True
    'Attribute VB_Exposed = True[/VBA]
    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 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.
    K :-)

  5. #5
    The code did not start when I restart outlook. Maybe missing some settings? I also change the security level to low. Thanks

  6. #6
    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.

  7. #7
    I test it in another pc in the same network and it's ok!
    So something wrong with outlook installation, or something else.
    Thanks

  8. #8
    I want to make it work in another mailbox (shared). How can I make it to be my default inbox?

  9. #9
    VBAX Regular
    Joined
    Feb 2008
    Posts
    6
    Location

    Thumbs up More than one email accounts

    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...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •