VB script to save email attachments, but only want only attachment if there are multiple in an email

0

I'm using a similar code to the below and activating it within email rules 'run a script' and it is working fine to save attachments as certain emails come in. However, if there are multiple attachments in an email it cycles through saving them and lands on the last one. Is there a way I can tell it within the code to only save the "x" attachment, ie. only the first attachment or only the fourth attachment, etc?

*If you want to process attachments on specific e-mails, this is what I use. It works perfectly for me in Outlook 2013:

Public Sub saveAttachtoDisk(itm As Outlook.MailItem)
Dim objAtt As Outlook.Attachment
Dim saveFolder As String
saveFolder = "c:\temp"
     For Each objAtt In itm.Attachments
          objAtt.SaveAsFile saveFolder & "\" & objAtt.DisplayName
          Set objAtt = Nothing
     Next
End Sub

The last part of the rule is the run a script. enter image description here For others that are not familiar with Outlook VBA, you need to bring up the Developer Ribbon. enter image description here Paste the code above, save the VBA, then reference it in your rule. enter image description here shareedit

answered Mar 2 '15 at 17:12*

user764995

Posted 2017-08-25T21:11:32.123

Reputation: 1

(1) If you are posting somebody else’s code, you must give credit to the source, both by name and by link.  (2) Have you tried anything?  (If so, what?)  If you want to use VBA, and you want to make tiny changes to existing code, you should try to learn a little about the language. – Scott – 2017-08-25T21:40:43.930

@Scott, sorry I'm new to this forum and also new to VBA....but I'm trying to learn and that's why I'm asking a question. I have not tried anything to this point bc I'm not sure where to start. – user764995 – 2017-08-25T21:51:43.990

No answers