I have follow all the instructions but it doesn't work, " Compile error : Syntax error"
Can you help me ? Please
Kutools for Excel is a powerful add-in that frees you from performing time-consuming operations in Excel, such as combine sheets quickly, merge cells without losing data, paste to only visible cells, count cells by color and so on. 300+ powerful features / functions for Excel 2019, 2016, 2013, 2010, 2007 or Office 365!
It enables tabbed browsing, editing, and managing of Microsoft Office applications. You can open multiple documents / files in a single tabbed window, such as using the browser IE 8/9/10, Firefox, and Google Chrome. It's compatible with Office 2019, 2016, 2013, 2010, 2007, 2003 or Office 365. Demo
Kutools for Outlook is a powerful add-in that frees you from time-consuming operations which majority of Outlook users has to perform daily! It can save your time from using Microsoft Outlook 2019, 2016, 2013, 2010 or Office 365!
Kutools for Word is a powerful add-in that frees you from time-consuming operations which majority of Word users have to perform daily! It can save your time from using Microsoft Word / Office 2019, 2016, 2013, 2010, 2007, 2003 or Office 365!
Restores the old look and menus of Office 2003 to Microsoft Office 2019, 2016, 2013, 2010, 2007 or Office 365. Don’t lose time in finding commands on the new Ribbon. Easy to deploy to all computers in enterprises and organizations.
If you are working with Microsoft Outlook 2010 and 2007, you will find that there is no build-in in Outlook to change the email to pdf format. You need to convert the email to pdf file by some related add-ins or with VBA code. With the following article, you will easily save email as pdf file in Outlook.
Save or Export Multiple emails to other fomat files(PDF/HTML/WORD/EXCEL) in Outlook
|Sometimes, you may want to save or export the emails to a folder as other format files, such as PDF, Word or Excel files in Outlook. In Outlook, neither of the Save as and Export function can handle this job. However, Kutools for Outlook's Save as file utility can export multiple emails to a folder as files with multiple formats at once time . Click for 45 days free trial!|
|Kutools for Outlook: with dozens of handy Outlook add-ins, free to try with no limitation in 45 days.|
1. Firstly you should select the email that you want to save as PDF.
2. Press Alt + F11 to launch the Microsoft Visual Basic for Applications window.
3. Click Insert > Module, then copy and paste the following VBA code to the Module window.
The VBA code of saving email as PDF file:
Sub SaveAsPDFfile() Dim MyOlNamespace As NameSpace Dim MySelectedItem As MailItem Dim Response As String Dim FSO As Object, TmpFolder As Object Dim tmpFileName As String Dim wrdApp As Object Dim wrdDoc As Object Dim bStarted As Boolean Dim dlgSaveAs As FileDialog Dim fdfs As FileDialogFilters Dim fdf As FileDialogFilter Dim i As Integer Dim WshShell As Object Dim SpecialPath As String Dim msgFileName As String Dim strCurrentFile As String Dim strName As String Dim oRegEx As Object Dim intPos As Long Set MyOlNamespace = Application.GetNamespace("MAPI") Set MySelectedItem = ActiveExplorer.Selection.Item(1) Set FSO = CreateObject("Scripting.FileSystemObject") tmpFileName = FSO.GetSpecialFolder(2) strName = "email_temp.mht" tmpFileName = tmpFileName & "\" & strName MySelectedItem.SaveAs tmpFileName, 10 On Error Resume Next Set wrdApp = GetObject(, "Word.Application") If Err Then Set wrdApp = CreateObject("Word.Application") bStarted = True End If On Error GoTo 0 Set wrdDoc = wrdApp.Documents.Open(FileName:=tmpFileName, Visible:=False, Format:=7) Set dlgSaveAs = wrdApp.FileDialog(msoFileDialogSaveAs) Set fdfs = dlgSaveAs.Filters i = 0 For Each fdf In fdfs i = i + 1 If InStr(1, fdf.Extensions, "pdf", vbTextCompare) > 0 Then Exit For End If Next fdf dlgSaveAs.FilterIndex = i Set WshShell = CreateObject("WScript.Shell") SpecialPath = WshShell.SpecialFolders(16) msgFileName = MySelectedItem.Subject Set oRegEx = CreateObject("vbscript.regexp") oRegEx.Global = True oRegEx.Pattern = "[\/:*?""<>|]" msgFileName = Trim(oRegEx.Replace(msgFileName, "")) dlgSaveAs.InitialFileName = SpecialPath & "\" & msgFileName If dlgSaveAs.Show = -1 Then strCurrentFile = dlgSaveAs.SelectedItems(1) If Right(strCurrentFile, 4) <> ".pdf" Then Response = MsgBox("Sorry, only saving in the pdf-format is supported." & _ vbNewLine & vbNewLine & "Save as pdf instead?", vbInformation + vbOKCancel) If Response = vbCancel Then wrdDoc.Close 0 If bStarted Then wrdApp.Quit Exit Sub ElseIf Response = vbOK Then intPos = InStrRev(strCurrentFile, ".") If intPos > 0 Then strCurrentFile = Left(strCurrentFile, intPos - 1) End If strCurrentFile = strCurrentFile & ".pdf" End If End If wrdApp.ActiveDocument.ExportAsFixedFormat OutputFileName:= _ strCurrentFile, _ 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:=False End If Set dlgSaveAs = Nothing wrdDoc.Close If bStarted Then wrdApp.Quit Set MyOlNamespace = Nothing Set MySelectedItem = Nothing Set wrdDoc = Nothing Set wrdApp = Nothing Set oRegEx = Nothing End Sub
Note: This VBA code have successfully tested in Outlook 2007 and 2010
4. Click to run the code.
5. There will be a File Save dialog popping up while the code is running. Select a path to save the file, name it, and finally click on Save button.
6. When the code finish running, the email have successfully converted to pdf file.
With Kutools for Outlook installed, you can use its Bulk Save utility to quickly save or export the selected emails to PDF files/Excel files/CSV files or other file formats.