The other thing I just realized is that if I try to convert '.txt' file into .pdf and save down on the network then it doesn't work with PropertyAccessor. Please see below the code. If I don't use PropertyAccessor class then text files get converted to pdf and get saved down but otherwise it just ignores text files:
Code:
Private Sub SaveAttachments(olItem As Object)
Dim olAttach As Attachment
Dim strFName As String
Dim strExt As String
Dim myNameSpace As Outlook.NameSpace
Dim myInbox As Outlook.Folder
Dim myDestFolder As Outlook.Folder
Dim myItems As Outlook.Items
Dim j As Long
Dim olInsp As Inspector
Dim oRng As Object
Dim strTemp As String
Dim intPos As Integer
Dim olkPA As Object 'propertyAccessor
Const PR_ATTACHMENT_HIDDEN = "http://schemas.microsoft.com/mapi/proptag/0x7FFE000B"
strTemp = Environ("TEMP") & ""
Set myNameSpace = Application.GetNamespace("MAPI")
Set myInbox = myNameSpace.GetDefaultFolder(olFolderInbox)
Set myItems = myInbox.Items
Set myDestFolder = myInbox.Folders("Completed")
If Not TypeName(olItem) = "MailItem" Then GoTo lbl_Exit
CreateFolders strSaveFldr
' To save email message body as pdf
SaveAsPDFfile olItem
' To save attachments as pdf.
If olItem.Attachments.Count > 0 Then
For j = 1 To olItem.Attachments.Count
Set olAttach = olItem.Attachments(j)
' New lines of code to exclude embedded attachments.
' Set olkPA = olAttach.PropertyAccessor
' If olkPA.GetProperty(PR_ATTACHMENT_HIDDEN) = False Then
Select Case LCase(Mid(olAttach.FileName, InStrRev(olAttach.FileName, Chr(46))))
Case ".docx", ".doc", ".dot", ".docm", ".dotm", ".txt"
On Error Resume Next
olAttach.SaveAsFile strTemp & olAttach.FileName
Set wdApp = GetObject(, "Word.Application")
If Err Then
Set wdApp = CreateObject("Word.Application")
End If
On Error GoTo 0
wdApp.Visible = True
Set wdDoc = wdApp.Documents.Open(strTemp & olAttach.FileName)
intPos = InStrRev(olAttach.FileName, ".")
strFName = Left(olAttach.FileName, intPos - 1)
strFName = strFName & ".pdf"
strExt = Right(strFName, Len(strFName) - InStrRev(strFName, Chr(46)))
strFName = FileNameUnique(strSaveFldr, strFName, strExt)
wdDoc.ExportAsFixedFormat OutputFilename:=strSaveFldr & strFName, _
ExportFormat:=17, _
OpenAfterExport:=False, _
OptimizeFor:=0, _
Range:=0, _
From:=0, _
To:=0, _
Item:=0, _
IncludeDocProps:=True, _
KeepIRM:=True, _
CreateBookmarks:=0, _
DocStructureTags:=True, _
BitmapMissingFonts:=True, _
UseISO19005_1:=True
wdDoc.Close 0
wdApp.Quit
'If bWordWasNotRunning = True Then wdApp.Quit
Case ".pdf", ".jpg", ".jpeg"
strFName = olAttach.FileName
strExt = Right(strFName, Len(strFName) - InStrRev(strFName, Chr(46)))
strFName = FileNameUnique(strSaveFldr, strFName, strExt)
olAttach.SaveAsFile strSaveFldr & strFName
End Select
olItem.Categories = ""
olItem.FlagStatus = olFlagComplete
olItem.UnRead = False
olItem.Save
' End If
Next j
' olItem.Save
End If
olItem.Move myDestFolder
Set olItem = myItems.FindNext
lbl_Exit:
Set olAttach = Nothing
Set olItem = Nothing
Exit Sub
End Sub