-2

I need to write an Outlook macro that saves attachments from mails which have specified title beginnings (for example: "Report..") OR have specified senders. I haven't programmed in Outlook VBA, so i don't know how to begin. Can you help?

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
  • You need to show what did you try and wasn't working for you, otherwise the question is too broad. The following may be the start: [Save attachments](https://stackoverflow.com/questions/15531093/save-attachments-to-a-folder-and-rename-them/15532110) and [Search for Outlook Email based on Sender, Subject](https://stackoverflow.com/questions/47927567/search-for-outlook-email-based-on-sender-subject-and-todays-date). Please do you research first. – Slava Ivanov Jul 31 '18 at 13:20
  • https://stackoverflow.com/a/43080675/4539709 – 0m3r Jul 31 '18 at 19:12

1 Answers1

0

I believe this will do what you want.

Sub SetFlagIcon()

Const olFolderInbox = 6

Set objOutlook = CreateObject("Outlook.Application")
Set objNamespace = objOutlook.GetNamespace("MAPI")
Set objFolder = objNamespace.GetDefaultFolder(olFolderInbox)

Set colItems = objFolder.Items

For Each objMessage In colItems
If objMessage.SenderEmailAddress = "someone@gmail.com" Then
    intCount = objMessage.Attachments.Count
    If intCount > 0 Then
        For i = 1 To intCount
            objMessage.Attachments.Item(i).SaveAsFile "C:\your_path_here\Desktop\" & _
                objMessage.Attachments.Item(i).FileName
        Next
    End If
End If
Next

End Sub

Please see the links below for some other ideas of where to go with this.

https://www.extendoffice.com/documents/outlook/3747-outlook-auto-download-save-attachments-to-folder.html

https://www.pixelchef.net/content/rule-autosave-attachment-outlook

ASH
  • 20,759
  • 19
  • 87
  • 200