If you would like to auto save the email as a PDF file when assigning a specific color category to it, you can utilize the method introduced in this article.
In order to better manage the emails, you may prefer to utilize color categories to classify and distinguish them. For instance, for the emails which are considerably important, you can assign the custom color category named “Important” to them. Moreover, for these important emails, you may want to save them to local drive. As we all know, Outlook only permit to save emails in TXT, HTML, MHT and MSG format. Therefore, if you would like to save emails as PDF files, you should seek other means, such as applying VBA codes. Now, in the followings, we will expose the elaborate steps and codes, which can let Outlook auto save the email as PDF if you assign a specified color category to it.
Auto Save the Email as a PDF File When Assigning a Specific Color Category to It
- At the very outset, start your Outlook program.
- Then press “Alt + F11” key buttons.
- In the subsequent VBA editor window, you can open the “ThisOutlookSession” project.
- Next copy and paste the following VBA codes into it.
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
- After that, sign this code.
- Later change your Outlook macro settings to permit the signed macros.
- Finally you can restart Outlook to activate the new VBA project.
- From now on, every time when you assign the predefined color category to a mail, it will be saved as PDF in the predetermined folder.
Get Rid of Painful PST Troubles
Perhaps you have ever encountered various issues in your Outlook. How do you deal with them in general? As usual, to fix PST small errors, you can simply utilize the inbox repair tool – Scanpst.exe. However, for those serious troubles, you had better resort to a more powerful and robust repair tool like DataNumen Outlook Repair.
Shirley Zhang is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including damaged mdf and outlook repair software products. For more information visit www.datanumen.com