Sunday, February 13, 2011

How to Save Word Docs to PDF in VBA


Enable PDF Support in Word
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. 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. 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
4. 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.'
5. 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.
6. 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
7. Click the 'File' menu and click 'Close and Return to Microsoft Word.'
8. 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.
9. 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.'

Blogger news