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*

  • (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 Aug 25 '17 at 21:40
  • @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 Aug 25 '17 at 21:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.