How to Save Word Docs to PDF in VBA

Written by matthew schieltz
  • Share
  • Tweet
  • Share
  • Email

Microsoft Word 2007 comes with a Visual Basic for Applications (VBA) code editor in which you can create controls that allow you to perform functions that ordinarily may not be available. With Word 2007, you can use the VBA code editor to save your Word documents in PDF form, which can be handy if you want to distribute your reports and documents in a format other than the ".docx" file format that Word uses. Before you can use a VBA code to save documents in PDF form, however, you must enable support in Microsoft Word for the PDF format through a free Microsoft add-in.

Skill level:
Moderately Easy

Other People Are Reading

Things you need

  • Microsoft save as PDF or XPS add-in

Show MoreHide


    Enable PDF Support in Word

  1. 1

    Open Microsoft Word 2007. Click the blue help icon in the top, right corner of the program. Type "pdf and xps file formats" in the Word Help search box and press "Enter." Click the "Print, share and protect files in the PDF and XPS file formats" search result.

  2. 2

    Click "Install and use the Save as PDF or XPS add-in from Microsoft" in the "What do you want to do" section. Click the blue-formatted Internet link that reads "Microsoft Save as PDF or XPS Add-in for 2007 Microsoft Office programs" to be taken to the add-in download page. Close the Microsoft Word program.

  3. 3

    Click the "Download" button on the add-in page. Save the file to your computer. Double-click the file to open it. Click the check-box to accept the Microsoft Software License Terms. Click "Continue" and wait for the installation to complete.

    Create and Run VBA Code

  1. 1

    Open a Microsoft Word document that you want to convert to PDF. Click the Office button and select "Word Options." Click the "Show Developer tab in the Ribbon" check box to enable it. Click "OK."

  2. 2

    Click the "Developer" tab in the Ribbon. Click "Macros" in the "Code" group. Type "SaveToPDF" or another name of your choice in the "Macro name" box. Click the "Create" button.

  3. 3

    Type the following VBA code lines, or copy and paste them, in the "New Macros (Code)" window in the line directly above the "End Sub" line:

    ActiveDocument.ExportAsFixedFormat OutputFileName:= _

    ActiveDocument.Path & "\" & ActiveDocument.Name & ".pdf", ExportFormat:= _

    wdExportFormatPDF, OpenAfterExport:=False, OptimizeFor:= _

    wdExportOptimizeForPrint, Range:=wdExportAllDocument, _

    Item:=wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, _

    CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _

    BitmapMissingFonts:=True, UseISO19005_1:=False

  4. 4

    Click the "File" menu and click "Close and Return to Microsoft Word."

  5. 5

    Click "Macros" in the "Code" group in the "Developer" tab. Click the name of your macro to highlight it if it is not already selected. Click "Run" to run the VBA code and automatically save the Word document as a PDF file. Navigate to the folder location on your computer in which your Word document is saved to find the PDF version of the file.

  6. 6

    Open any other Word documents that you want to save as a PDF. Click the "Developer" tab, click "Macros," select the name of the macro you created and click "Run."

Don't Miss

  • All types
  • Articles
  • Slideshows
  • Videos
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the site, you consent to the use of cookies. For more information, please see our Cookie policy.