Outlook VBA Addin

I found this code snippet on another site: https://www.extendoffice.com/documents/outlook/3747-outlook-auto-download-save-attachments-to-folder.html

This works! Which is great. However I would like to modify this to only grab PDF files from the emails and prepend a date to the file name (yyyymmdd - original filename). I have zero programming knowledge. I have found a few different sites and have tried to modify but it just breaks the code and the script stops working. Any assistance would be appreciated.

Public Sub SaveAttachmentsToDisk(MItem As Outlook.MailItem)
Dim oAttachment As Outlook.Attachment
Dim sSaveFolder As String
sSaveFolder = "C:\Users\DT168\Documents\outlook-attachments\"
For Each oAttachment In MItem.Attachments
oAttachment.SaveAsFile sSaveFolder & oAttachment.DisplayName
Next
End Sub
LVL 1
Ryan RoodAsked:
Who is Participating?
 
Rgonzo1971Connect With a Mentor Commented:
Hi,

pls try
Public Sub SaveAttachmentsToDisk(MItem As Outlook.MailItem)
Dim oAttachment As Outlook.Attachment
Dim sSaveFolder As String
sSaveFolder = "C:\Users\DT168\Documents\outlook-attachments\"
For Each oAttachment In MItem.Attachments
    If oAttachment.FileName Like "*.pdf" Then
        oAttachment.SaveAsFile sSaveFolder & Format(Date, "yyyymmdd") & oAttachment.DisplayName
    End If
Next
End Sub

Open in new window

Regards
1
 
Ryan RoodAuthor Commented:
Thank you so much! That is exactly what I needed! :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.