Solved

VB Script to download outlook mail attachments

Posted on 2016-09-29
2
30 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 14

Accepted Solution

by:
Alexei Kuznetsov (Outlook MVP) 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 (Outlook MVP)
ID: 41847977
The answer is given.
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Migrate Thunderbird to Outlook 6 85
outlook 365 3 53
exchange, IIS, AUTODISCOVER, OWA 18 53
Transfer Outlook 2013 Autofill data 6 14
What does UTC stand for?  “Coordinated Universal Time” – Think of this as the true time on Planet Earth that never changes with the exception of minor leap seconds here and there to account for the changes in the planet's rotation.   What does th…
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
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 …

740 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