locked
Macro to Open Outlook Attachments RRS feed

  • Question

  • I have a macro which is supposed to look for any attachments in any e-mails in a specific outlook folder, find any attachments and save them into a location.

    I have an outlook rule set up that sends the specific emails that I want to the outlook folder my macro looks in, and then fires the macro. For some reason the macro doesn't fire on my computer automatically, but it does on another computer. The email comes in and the rule drops it into the folder, but the macro doesnt run. When I run the macro later manually through VB Editor, it downloads the attachment and saves it in the right place. What could be the issue? 

    I have checked to make sure folder and path names are correct (either way if they were wrong the macro wouldn't run properly when I run it manually). 

    Outlook rule:

    Apply this rule after the message arrives 

    from xxxxxxxxxxxx

    and with xxxx in the subject

    and on this machine only

    move it to the xxxxx folder

    and run Project1.ThisOutlookSession.Save

    Macro:


    Sub Save(item As Outlook.MailItem)

    Dim olApp As Outlook.Application
    Dim objNS As Outlook.NameSpace
    Dim olFolder As Outlook.MAPIFolder
    Dim msg As Outlook.MailItem

    Set olApp = Outlook.Application
    Set objNS = olApp.GetNamespace("MAPI")
    Set olFolder = objNS.GetDefaultFolder(olFolderInbox)
    Set olFolder = olFolder.Folders("xxxxxxx")
    Set oApp = CreateObject("Shell.Application")

    For Each myitem In olFolder.Items
      For Each att In myitem.Attachments
            att.SaveAsFile "\\.............\" & att.FileName
            myitem.Attachments.Remove 1
            myitem.Save
        Next
    Next

    End Sub

    Wednesday, February 13, 2013 7:41 PM

Answers

  • Hi Morganlndust,

    Thanks for posting in the MSDN Forum.

     and run Project1.ThisOutlookSession.Save

    Please set your subroutine in a Model instead of ThisOutlookSession.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by 许阳(无锡) Monday, February 18, 2013 6:42 AM
    • Unmarked as answer by MorganIndust Monday, February 25, 2013 6:03 PM
    • Marked as answer by Quist Zhang Monday, March 11, 2013 7:39 AM
    Thursday, February 14, 2013 7:55 AM
  • Hi MorganIndust,

    By

    and run Project1.ThisOutlookSession.Save

    Tom means 

    Hope it helps.

    Best regards,


    Quist Zhang [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Quist Zhang Monday, March 11, 2013 7:39 AM
    Monday, March 11, 2013 7:39 AM

All replies

  • Hi Morganlndust,

    Thanks for posting in the MSDN Forum.

     and run Project1.ThisOutlookSession.Save

    Please set your subroutine in a Model instead of ThisOutlookSession.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by 许阳(无锡) Monday, February 18, 2013 6:42 AM
    • Unmarked as answer by MorganIndust Monday, February 25, 2013 6:03 PM
    • Marked as answer by Quist Zhang Monday, March 11, 2013 7:39 AM
    Thursday, February 14, 2013 7:55 AM
  • Hi Tom, 

    Can you elaborate? I'm kind of new to this so I don't know how I can put the code in a 'model'

    Tuesday, February 19, 2013 1:55 PM
  • Hi MorganIndust,

    By

    and run Project1.ThisOutlookSession.Save

    Tom means 

    Hope it helps.

    Best regards,


    Quist Zhang [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Quist Zhang Monday, March 11, 2013 7:39 AM
    Monday, March 11, 2013 7:39 AM
  • Hi,

    In Set olFolder = olFolder.Folders("xxxxxxx"), what put in "xxxxxxx"?

    Thanks

    Thursday, July 25, 2013 8:26 PM