This VBA script is designed to extract attachments from emails in a specific folder in your Outlook account. It cycles through the emails in the selected account's incoming folder, checks if they contain attachments, and if the sender's email address matches the specified address, saves the attachments to a predefined destination folder.
Enable the developer tab: File>Options>Customize Ribbon. In the box on the right, select the 'Developer' checkbox.
- Open Microsoft Outlook.
- Press
ALT + F11
to open the Visual Basic for Applications Editor. - Create a new module (if you don't already have one) and paste the provided code into it.
- Modify the
strSaveFolder
andtargetEmail
variables according to your needs:strSaveFolder
: Specifies the folder where attachments will be saved. By default, it is set to"C:\Users\ellencrist\Downloads\TestFolder\"
. Replace with the desired path.targetEmail
: Enter the email address of the sender whose emails you want to filter and extract attachments.
- Modify the
Set targetFolder
line to point to the correct folder in your Outlook account. - Close the VBA Editor and return to Outlook.
- Run the script by pressing
ALT + F8
, select "Save Attachments" and click "Run".
Note: Make sure Microsoft Outlook referral is enabled.
- The script starts by creating an instance of Outlook and getting the Outlook namespace.
- It specifies the destination folder where the attachments will be saved and the email address of the sender whose emails will be filtered.
- The script iterates over the emails in the specific account's incoming folder.
- Checks whether the email contains attachments and whether the sender's email address matches the specified address.
- If both conditions are met, the script cycles through the email attachments and saves them in the destination folder.
- After completing the iteration, displays a message stating how many attachments were saved or if no attachments were found.
- Make sure you replace the
targetFolder
variable value with the correct folder path in your Outlook account. - This script is designed to run in Microsoft Outlook and requires permissions to access your email folders.
- Remember that Outlook automation can vary between different Outlook versions and security settings.