I have emails that I receive that have both PDF and TXT files attached. I need to just pull the TXT file attachments from the email and save to a folder on the network.
I have the following code (see attached code), but it is pulling both the PDF and TXT files, and as mentioned above I just want to save the TXT attachments.
What do I need to change/add in my existing code to do this?
Sub SaveOutlookAttachments(olkMessage As Outlook.MailItem)
Dim olkAttachment As Outlook.Attachment, _
objFSO As Object, _
strRootFolderPath As String, _
strFilename As String
'Path for where to save attachments
strRootFolderPath = "X:\sh_fox\FIR_TBT\2011\2011_ExceptionReports\2011_March\3-7-2011\"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set olkSourceFolder = Application.ActiveExplorer.CurrentFolder
If olkMessage.Attachments.Count > 0 Then
For Each olkAttachment In olkMessage.Attachments
strFilename = olkAttachment.FileName
intCount = 0
Do While True
If objFSO.FileExists(strRootFolderPath & strFilename) Then
intCount = intCount + 1
strFilename = "Copy (" & intCount & ") of " & olkAttachment.FileName
olkAttachment.SaveAsFile strRootFolderPath & strFilename
Set objFSO = Nothing
Set olkAttachment = Nothing
Set olkMessage = Nothing