A macro is a piece of executable Visual Basic for Applications code, or VBA, in Microsoft Word. A macro helps you customise Word to fit your needs and replace repetitive tasks. For example, if you constantly find yourself converting Word documents to PDFs, a macro button can replace several keystrokes with a single macro function. You write the code once and use it whenever you want to turn a Word document into a PDF. VBA is built into Word 2007 and Word 2010.
- Skill level:
Other People Are Reading
Things you need
- Word 2007 or Word 2010
Press "Alt" and "F11" in Word. This opens the Visual Basic Editor, or VBE, where you enter the VBA code.
Click on "Insert" and then click on "Module" to open a new window.
Cut and paste the following code into the window:
' WordtoPDF Macro
ActiveDocument.ExportAsFixedFormat OutputFileName:= _ "C:\Desktop\Doc1.pdf", ExportFormat:=wdExportFormatPDF, _ OpenAfterExport:=True, OptimizeFor:=wdExportOptimizeForPrint, Range:= _ wdExportAllDocument, From:=1, To:=1, Item:=wdExportDocumentContent, _ IncludeDocProps:=True, KeepIRM:=True, CreateBookmarks:= _ wdExportCreateNoBookmarks, DocStructureTags:=True, BitmapMissingFonts:= _ True, UseISO19005_1:=False
Modify the output file in the code to show where you would like the PDF to end up. In the above example, the file is sent to the Desktop.
Press "F5" to run the program.
Tips and warnings
- Press "alt" and "F11" to toggle between the VBE and the regular Word window. To run the code without entering the VBE, click on the "Developer" tab and then click on "Macros." Click on the macro name---(the macro name of this subroutine is WordtoPDF---and then click on "Run."
- 20 of the funniest online reviews ever
- 14 Biggest lies people tell in online dating sites
- Hilarious things Google thinks you're trying to search for