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

Frank M

New Member
Outlook version
Outlook 2010 32 bit
Email Account
IMAP
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!
 

chiplad

New Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
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
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
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
 

chiplad

New Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
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.
 
Top