View Full Version : [SOLVED:] Connect with server mailbox (Outlook) and download attachment
sumair9142
08-13-2019, 01:22 AM
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.
Thanks.
Kenneth Hobs
08-14-2019, 08:04 AM
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.
Summary:
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.
See:
http://www.snb-vba.eu/VBA_Outlook_external_en.html#L_6.6.2
sumair9142
08-19-2019, 02:25 AM
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")
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.