

How To Save An Excel File As PDF Using VBA: Basic Code Examples (Examples #1 And #2).How To Save An Excel File As PDF Using VBA: The ExportAsFixedFormat Method.The following table of contents lists the different sections of this blog post. Explain how you can save each worksheet from an Excel workbook in a separate PDF file.Introduce some different ways in which you can specify the filename of the PDF file that results after the Excel to PDF conversion.Provide a thorough introduction to how you can use Visual Basic for Applications for purposes of adjusting the page setup attributes.In fact, in this blog post, I go much further than simply showing you how to simply convert Excel files to PDF. More precisely, I explain in detail how you can save Excel files as PDF using VBA, and provide 10 examples of VBA code that you can start using immediately. This particular Excel tutorial also focuses on the topic of working with Excel and PDF files. The reason why I write about PDF is relatively straightforward: PDF is one of the most widely used file formats. However, I've written several tutorials (such as here and here) that have to do with PDF and, more particularly, with the topic of converting PDF files to Excel. Kutools for Outlook,Includesġ00 powerful features and tools for Microsoft Outlook 2016, 2013, 2010 and Office 365.Power Spreadsheets focuses on Microsoft Excel. With above methods, you only can save one message as a PDF file at a time, if you want to batch convert multiple emails to separated PDF files, you can try Kutools for Outlook’s Bulk Save utility. Tip: If the code cannot run, you may try to go to Trust Center to check the Enable all macros option in Macro Settings section. Press F5 key to enable File Save dialog, select a folder to place the file and give it a name. StrCurrentFile = Left(strCurrentFile, intPos - 1) VbNewLine & vbNewLine & "Save as pdf instead?", vbInformation + vbOKCancel) Response = MsgBox("Sorry, only saving in the pdf-format is supported." & _

StrCurrentFile = dlgSaveAs.SelectedItems(1) MsgFileName = Trim(oRegEx.Replace(msgFileName, ""))ĭlgSaveAs.InitialFileName = SpecialPath & "\" & msgFileName Set oRegEx = CreateObject("vbscript.regexp") SpecialPath = WshShell.SpecialFolders(16)

Set WshShell = CreateObject("WScript.Shell") If InStr(1, fdf.Extensions, "pdf", vbTextCompare) > 0 Then Set dlgSaveAs = wrdApp.FileDialog(msoFileDialogSaveAs) Set wrdDoc = (FileName:=tmpFileName, Visible:=False, Format:=7) Set wrdApp = CreateObject("Word.Application") Set wrdApp = GetObject(, "Word.Application") TmpFileName = tmpFileName & "\" & strName Set FSO = CreateObject("Scripting.FileSystemObject") Set MyOlNamespace = Application.GetNamespace("MAPI") VBA: Convert email to pdf Sub SaveAsPDFfile() Click Insert > Module, and paste below code to the Module script. Select one email, and press Alt + F11 keys to enable the Microsoft Visual Basic for Applications window.Ģ. If you are working at Outlook 2007 or 2010, you can apply a VBA code to convert one email to PDF file.ġ. Note: This method only work in Outlook 2016. Now the selected message has been converted to a PDF file. Click Save, and click Cancel to stop printing. In the Save Print Output As dialog, select one path to place the file, and give it a name.ģ. Select the email you want to convert to PDF, click File > Print, select Microsoft Print to PDF from the Printer drop-down list, and click Print.Ģ. In Outlook, you can use the Print function to save one email as a PDF file.ġ. In Outlook, the Save As function only can save an email as HTML, TXT, MHT, MSG and Template format file, if you want to convert the email(s) to PDF file(s), how can you do? In this article, I introduce some tricks on solving this problem.Ĭonvert one email to PDF file with Print functionĬonvert batch emails to separated PDF files with Save as File utility How to batch convert multiple emails to pdf files in Outlook?
