Solved

VB Script to download outlook mail attachments

Posted on 2016-09-29
2
25 Views
Last Modified: 2016-10-18
Hi All,
I am using a VB Script on Outlook that downloads any attachment in an outlook mail to a specific folder.
Then i am calling this script in an Outlook Rule where i define to which mail this script has to work for.
The issue that i am facing is that the script works from new-old fashion providing me oldest attachment and not newest attachment.This is for the attachments with same name in every mail.
What shall i add to the below script so that it moves in old - new sort downloading new attachments to override old attachments with the same name.
 
VB Script used:
Public Sub saveAttachtoDisk(itm As Outlook.MailItem)
Dim objAtt As Outlook.Attachment
Dim saveFolder As String
saveFolder = "E:\Projects\Takeda\Data\Zipped Incremental data\incremental\"      
For Each objAtt In itm.Attachments          
objAtt.SaveAsFile saveFolder & "\" & objAtt.DisplayName          
    Set objAtt = Nothing      
Next
End Sub
0
Comment
Question by:Pulkit Thukral
  • 2
2 Comments
 
LVL 14

Accepted Solution

by:
Alexei Kuznetsov earned 500 total points (awarded by participants)
ID: 41822219
Your script effectively overwrites the existing file. How do you run your rules? Manually or just automatically for incoming emails? If manually, the order of emails is not guaranteed at all.

In order to process emails in a particular order (by date, for instance) you need to create a much more complex script that will get emails in a sorted order, check all required conditions and save attachments.

Alternatively, you can add the current date (and maybe part of the time) to the name of your saveFolder.
0
 
LVL 14

Expert Comment

by:Alexei Kuznetsov
ID: 41847977
The answer is given.
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Follow this checklist to learn more about the 15 things you should never include in an email signature from personal quotes, animated gifs and out-of-date marketing content.
How to resolve IMCEAEX NDRs in Exchange or Exchange Online related to invalid X500 addresses.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question