VBA script to auto download attachments and rename file according to subject line

Status
Not open for further replies.
After you identify the message, you can use a case statement or an array to set the folder.
Select Case True
case instr(1,item.subject,"phrase") >0
saveFolder = "path"

case instr(1,item.subject,"phrase2") >0
saveFolder = "new path"
end select

Thanks Diane!
 
Hi guys,

I think I have a similar problem!

I need to save attachments with the filenames as the email subject. I am using a script (below) and it works fine on the first attachment but doesn't process multiple attachments. I need it to save the attachments with subject as filename and append _1, _2, _3 etc.

What am I doing wrong?

Public Sub saveAttachtoDisk(itm As Outlook.MailItem)

Dim objAtt As Outlook.Attachment

Dim saveFolder As String

saveFolder = "C:\Users\chrisf\Desktop\Image Test\"

MSN = Trim(itm.Subject)


For Each objAtt In itm.Attachments

If objAtt.FileName <> "image001.gif" Then

objAtt.SaveAsFile saveFolder & "\" & itm.Subject & ".JPG"

End If


Set objAtt = Nothing

Next

End Sub
 
you need to add a number to the code that saves it. This is one way to do it
Code:
i =  itm.Attachments.count
For Each objAtt In itm.Attachments

If objAtt.FileName <> "image001.gif" Then

objAtt.SaveAsFile saveFolder & "\" & itm.Subject &  i & ".JPG"

End If
i = i - 1
 
you need to add a number to the code that saves it. This is one way to do it
Code:
i =  itm.Attachments.count
For Each objAtt In itm.Attachments

If objAtt.FileName <> "image001.gif" Then

objAtt.SaveAsFile saveFolder & "\" & itm.Subject &  i & ".JPG"

End If
i = i - 1

Diane - thank you so much! You are a true genius :) And thanks for sharing, so so helpful.
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
FryW Need help modifying a VBA script for in coming emails to auto set custom reminder time Outlook VBA and Custom Forms 0
J Outlook Rules VBA Run a Script - Multiple Rules Outlook VBA and Custom Forms 0
A VBA Script - Print Date between first email in Category X and last email in Category Y Outlook VBA and Custom Forms 3
L Modifying VBA script to delay running macro Outlook VBA and Custom Forms 3
L Need help modifying a VBA script for emails stuck in Outbox Outlook VBA and Custom Forms 6
D.Moore VBA script fail after Office 365 update Using Outlook 8
S Change VBA script to send HTML email instead of text Outlook VBA and Custom Forms 3
dweller Outlook 2010 Rule Ignores VBA Script Outlook VBA and Custom Forms 2
N VBA Script to Open highlighted e-mail and Edit Message Outlook VBA and Custom Forms 5
K Outlook Archive to PST Files by Date Range VBA Script? Outlook VBA and Custom Forms 1
Peter H Williams Enable script containing VBA Outlook VBA and Custom Forms 12
R VBA Script Quick Parts Using Outlook 1
Q VBA Script to move item in secondary mailbox Outlook VBA and Custom Forms 2
N VBA Script to Send Automatic Emails from Outlook 2010 Outlook VBA and Custom Forms 1
O modify vba to run it as script rule Outlook VBA and Custom Forms 8
P How many subs can run in one outlook VBA script Using Outlook 5
J Email Parsing VBA Script for Outlook - NEEDED Outlook VBA and Custom Forms 7
P Vba script including macro appears in rules but wont run Outlook VBA and Custom Forms 6
R Adding vba to script list Outlook VBA and Custom Forms 4
F VBA script to highlight specific words Outlook VBA and Custom Forms 1
D VBA Script to extract text matching specific criteria Outlook VBA and Custom Forms 1
D VBA Script (Ask to where to save send mail) Outlook VBA and Custom Forms 1
M VBA script to allow mail merges of distribution groups? Using Outlook 7
Hudas Outlook VBA script reverting back to previous changes Outlook VBA and Custom Forms 2
J Outlook 2007 Rules & VBA: How to run a script on a report message (ReportItem) Using Outlook 14
V "Accept + Send the Response now", VBA script? Using Outlook 1
R Addins4Outlook TagIt! addin script or VBA module? Using Outlook 2
S Outlook VBA rule script to process both MailItem and MeetingItem Using Outlook 0
A VBA Script to Forward Spam to AntiSpam Provider Using "Blank" Form Outlook VBA and Custom Forms 2
L Limit VBA Script to one Outlook account Using Outlook 1
Hornblower409 Outlook VBA Code Example - Unified inbox in Outlook Classic Outlook VBA and Custom Forms 5
R VBA Macro for Archiving IMAP Emails to PST Outlook VBA and Custom Forms 3
E Need to digitally sign macro but VBA\Outlook crash Outlook VBA and Custom Forms 4
P ChatGPT (or equivalent) to write VBA code? Using Outlook 3
O VBA Only works once then doesn't work Outlook VBA and Custom Forms 2
M Use VBA to filter contacts Using Outlook 2
C VBA in "New Outlook?" Using Outlook 0
efire9207 VBA Outlook Contacts Outlook VBA and Custom Forms 6
B Requesting VBA code to make Outlook prompt for confirmation when deleting a task? Outlook VBA and Custom Forms 4
M Outlook 365 VBA Auto-Forward Only the first of Duplicate Emails Outlook VBA and Custom Forms 2
N VBA Code Not Working correctly Outlook VBA and Custom Forms 1
L VBA to Triage Incoming Email Outlook VBA and Custom Forms 0
J Outlook VBA to send from Non-default Account & Data Files Outlook VBA and Custom Forms 4
H using VBA to edit subject line Outlook VBA and Custom Forms 0
G Get current open draft message body from VBA Outlook VBA and Custom Forms 1
P VBA to add email address to Outlook 365 rule Outlook VBA and Custom Forms 0
M Outlook 2016 outlook vba to look into shared mailbox Outlook VBA and Custom Forms 0
V VBA Categories unrelated to visible calendar and Visual appointment Categories Outlook VBA and Custom Forms 2
D Outlook VBA forward the selected email to the original sender’s email ID (including the email used in TO, CC Field) from the email chain Outlook VBA and Custom Forms 2
R Outlook 365 VBA AUTO SEND WITH DELAY FOR EACH EMAIL Outlook VBA and Custom Forms 0

Similar threads

Back
Top