How do I save Outlook attachments to folder (multiple file types)? pdf doc jpg

I found script for a module that would move all pdf attachments to a specific folder on my HD. I was wondering how to include jpg and doc fomats too?
Here is the code I used:
Sub SaveAttachmentsToDisk(Item As Outlook.MailItem)
    Dim olkFolder As Outlook.MAPIFolder, _
        olkAttachment As Outlook.Attachment, _
        objFSO As Object, _
        strRootFolderPath As String, _
        strFilename As String, _
        intCount As Integer
    'Change the path on the following line to the folder you want the attachments save in
    strRootFolderPath = "C:\eeTesting\Attachments\"
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set olkFolder = Application.ActiveExplorer.CurrentFolder
    If Item.Attachments.Count > 0 Then
        For Each olkAttachment In Item.Attachments
            If objFSO.GetExtensionName(LCase(olkAttachment.FileName)) = "pdf" Then
                strFilename = olkAttachment.FileName
                intCount = 0
                Do While True
                    If objFSO.FileExists(strRootFolderPath & strFilename) Then
                        intCount = intCount + 1
                        strFilename = "Copy (" & intCount & ") of " & olkAttachment.FileName
                        Exit Do
                    End If
                olkAttachment.SaveAsFile strRootFolderPath & strFilename
            End If
    End If
    Set objFSO = Nothing
    Set olkAttachment = Nothing
    Set olkFolder = Nothing
End Sub
Who is Participating?
IceBergConnect With a Mentor Commented:
I assume you've tried changing the line:

     If objFSO.GetExtensionName(LCase(olkAttachment.FileName)) = "pdf" Then

to be
     If objFSO.GetExtensionName(LCase(olkAttachment.FileName)) = "pdf" or objFSO.GetExtensionName(LCase(olkAttachment.FileName)) = "jpg" or objFSO.GetExtensionName(LCase(olkAttachment.FileName)) = "doc" Then

yesiamcConnect With a Mentor Author Commented:
I did not! I will give it a try. thanks for the quick response.
yesiamcAuthor Commented:
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.