none
Run Outlook Code each time Outlook is started RRS feed

  • Question

  • Hello All,

       I have a outlook code which checks for mails in specific folder and with specific Subject line. If they are found, it picks up the attachment from that mail and saves it to a shared folder. The code works fine. But I need help on one thing here.

    1. How do I Schedule this to run each time I start outlook. I tried calling the module function in the Application_Startup() under ThisOutlookSession.

    For some reason, this does not work. Each time I close Outlook and its up and running, I notice that the outlook code automatically goes into Design Mode.

    Secondly, more surprisingly, when I try to bring it out of Design mode it does not allow me to. The error message

    "The Macros in this project are disabled. Please refer to the online help or documentation of the host application to determine how to enable macros."

    And then I am not allowed to get out of the Design Mode. The only solution I found is that:


    1. close outlook

    2. I need to go into "c:\Users\MYID\AppData\Roaming\Microsoft\Outlook" and VbaProject.OTM

    3. start outlook and put in the code back in there.

    It would be very helpful if some one could help me understand why does it goto Desing Mode each time Outlook is shutdown and Started.

    Secondly, will the code run automatically if i put it under Application_Startup() ?

    Tuesday, September 11, 2018 8:52 AM

All replies

  • Hi Praveen Kulkarni,

    As for “goto Desing Mode each time Outlook is shutdown and Started.” It is a common issue, many people have come across this issue. And yet we don’t have an official solution for this issue at the moment.

    According to my search and tests, This URL(the last answer in this URL) may be useful for you:

    https://social.msdn.microsoft.com/Forums/office/en-US/6500b26f-6cb1-4e3d-9d61-15850cfdcbdb/the-macros-in-this-project-are-disabled?forum=outlookdev

    For Application_Startup(), the code can run automatically if you put it under  Application_Startup(). 

    I read this in the following article: Application_Startmacros must be in ThisOutlookSession.

    article link : https://www.slipstick.com/developer/how-to-use-outlooks-vba-editor/

    Here is complete code:

    Public Sub Application_Startup()
    Dim appOutlook As Object
    Dim olNs As Object
    Dim olFolder As Object
        
        MsgBox "Welcome, " & Application.GetNamespace("MAPI").CurrentUser
        Set appOutlook = GetObject(, "Outlook.Application")
        'If appOutlook Is Nothing Then
        Set olNs = appOutlook.GetNamespace("MAPI")
        Set olFolder = olNs.Folders("yourname@yourname.com").Folders("yourFolderName");
        
        MsgBox olFolder
        Application.ActiveExplorer.WindowState = olMaximized
    End Sub


    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread.

    Wednesday, September 12, 2018 9:26 AM
  • Has this problem been solved?

    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread.

    Friday, September 14, 2018 2:51 AM