auto save email as pdf file in outlook

Victoria, Austria

hi,

I'm using windows7 and outlook2010

I need to save some emails as PDF to my computer. But I can't find a way to do that.
Moreover, this emails will alway be assigned a red color category, so I just guess if I can auto save those red color category emails as PDF format to my computer?
Thank you!

Haines, AK

Hello,snnisy

You can try to do that via VBA, here is a macro you can try :
In code: objMail.Categories = "Important" , you can change the categories name "Important" to the one your are using actually


Public WithEvents objExplorer As Outlook.Explorer
Public WithEvents objMail As Outlook.MailItem

Private Sub Application_Startup()
Set objExplorer = Outlook.Application.ActiveExplorer
End Sub

Private Sub objExplorer_SelectionChange()
On Error Resume Next
If objExplorer.Selection.Item(1).Class = olMail Then
Set objMail = objExplorer.Selection.Item(1)
End If
End Sub

Private Sub objMail_PropertyChange(ByVal Name As String)
If Name = "Categories" Then
'When the "Important" category is assigned to the selected email
If objMail.Categories = "Important" Then
Call SaveAsPDF(objMail)
End If
End If
End Sub

Private Sub SaveAsPDF(ByVal objSelectedMail As Outlook.MailItem)
Dim objFileSystem As Object
Dim strName, strFilePath As String
Dim objWordApp As Word.Application
Dim objWordDoc As Word.Document
Dim strPDF As String

Set objFileSystem = CreateObject("Scripting.FileSystemObject")

strName = objSelectedMail.Subject
'Remove the unsupported characters in the email subject
strName = Replace(strName, "/", "-")
strName = Replace(strName, "", "-")
strName = Replace(strName, ":", "-")
strName = Replace(strName, "?", "-")
strName = Replace(strName, Chr(34), "-")

'Firstly, save the email as a mht file in the temporary folder
strName = Format(objSelectedMail.ReceivedTime, "yyyy-mm-dd") & " - " & strName
strFilePath = objFileSystem.GetSpecialFolder(2) & "" & strName & ".mht"
objSelectedMail.SaveAs strFilePath, olMHTML

'Open the mht file in MS Word
Set objWordApp = CreateObject("Word.Application")
Set objWordDoc = objWordApp.Documents.Open(strFilePath, False)

'Change the local folder to save the PDF file
strPDF = "E:" & strName & ".pdf"

'Export the current mht file as a PDF file
objWordApp.ActiveDocument.ExportAsFixedFormat strPDF, wdExportFormatPDF

objWordDoc.Close
objWordApp.Quit
End Sub

More details at:

https://www.datanumen.com/blogs/auto-save-email-pdf-file-assigning-specific-color-category/

Hope it helps

This message was edited May 17, 2017 5:41 PM

Victoria, Austria

Hi, all

Thank you for your help. I think I get my solution. Good code! Thanks!

Post a Reply to this Thread

Please or sign up to post.
BACK TO TOP