Results 1 to 4 of 4

Thread: Excel VBA Help - Connect with server mailbox (Outlook) and download attachment

  1. #1

    Excel VBA Help - Connect with server mailbox (Outlook) and download attachment

    Hi Guys,

    I am new to VBA and new to this forum as well,
    i am trying to download email attachments using excel VBA.
    i want to connect to outlook shared mailbox.
    And on that mailbox i want to search for specific email using subject and download attachments from those email.

    Is there anyone who can help me in this regards,

    Appreciate for your time.

    Last edited by sumair9142; 08-13-2019 at 01:33 AM.

  2. #2
    VBAX Guru Kenneth Hobs's Avatar
    Nov 2005
    Tecumseh, OK
    Welcome to the forum!

    That can be a bit of a chore. One has to iterate the mail items in a folder first. What is the subject text? Then, save the attachments to a folder with a unique name for the mail items with that subject line string or partial string. e.g. Subject: Re: Inventory 123456. Partial string might be, "Inventory".

    For the first step and especially so for a "shared" mailbox, PM the results of this code below. Click my profile link, and then the Send Private Message. The string will contain an email address which one should not post in forums. Select the Outlook folder before running this code.
    Sub GetActiveFolder()  MsgBox outlook.ActiveExplorer.CurrentFolder.FolderPath
      Debug.Print outlook.ActiveExplorer.CurrentFolder.FolderPath
    End Sub
    The VBE, Visual Basic Editor, View menu can enable the Immediate window where Debug.Print results go after a Run. Copy that string and PM it to me.

    1. Send me full shared folder name from the code above.
    2. What is the subject string or partial string?
    3. Is there a preference for attachment filenames? e.g. 20190814 Invoice xxxx.pdf. Where the date is date received and xxxx is the next word after Invoice in the subject line.

  3. #3

  4. #4
    Hi Guys,
    Thank you for your responses, i found my answer, i already knew how to fetch emails from my own account but wasn't sure about shared mailbox, which i found that i need to mention the name of shared mailbox and set it to folder as below:
    Set Folder = Session.Folders("Name of Shared mailbox")
    Set Folder = Folder.Folders("Inbox")
    Set Folder = Folder.Folders("Name of Subfolder")

Posting Permissions

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