One of the most common word-processing related task for academics is to generate PDF versions of documents — for sharing with colleagues, for submission to a journal, for uploading to a publication page, et cetera. In LaTex, creating PDFs is a question of one simple command (plus a bit of fiddling with settings). In recent versions of Word, it is also pretty simple: just Save as… and select PDF. But that option is buried in the ribbon interface and involves quite a number of clicks. I generate PDFs practically everyday, so I wanted something easier. Enter Word macros.
The macros below do only one thing: they save the currently open file as PDF, by default in the same folder, with the same file name. The first will provide you with the option to change file name and location, the second is a straight export, no questions asked. Pick whichever one you like and add it to Word. Some steps for adding it as a button to a toolbar follow below.
Hang on, where do I put this code?, you ask. You can find out how to add a macro to Word here. Basically you create a new macro and paste the below code into it, then save. I could provide you with a downloadable .dot(x) file but that would only get you into trouble with all sorts of security restrictions in your browser or in Word, so doing it this way is easier.
Macro 1: Using the ‘Save as…’ window
This macro essentially just calls up the ‘Save as…’ window and pre-selects the PDF format. It will suggest a filename, which you can change; and it will warn you when you’re about to overwrite an existing file.
Sub Save_to_PDF() ' ' Save_to_PDF Macro ' ' With Dialogs(wdDialogFileSaveAs) .Format = wdFormatPDF .Show End With End Sub
Macro 2: No questions asked
This macro (from here, with helpful amendments by readers) goes straight for exporting. It won’t ask you anything and won’t warn you if a file is overwritten (which to me is precisely the point — I want the PDF always to correspond to the most recent version of the document).
Sub Silent_save_to_PDF() ' ' Silent Save_to_PDF Macro ' ActiveDocument.ExportAsFixedFormat OutputFileName:= _ Replace(ActiveDocument.FullName, ".docx", ".pdf") , _ ExportFormat:=wdExportFormatPDF, OpenAfterExport:=False, OptimizeFor:= _ wdExportOptimizeForPrint, Range:=wdExportAllDocument, Item:= _ wdExportDocumentContent, IncludeDocProps:=False, KeepIRM:=True, _ CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _ BitmapMissingFonts:=True, UseISO19005_1:=False End Sub
Advanced users will note that they can customize the output somewhat by changing the export settings. For instance, if you use it mainly for journal submissions, you might want to set
Adding your macro to the Quick Access Toolbar
Now we want to pick one of the macros and add it to a menu for true one-click access. I like the ‘quick access toolbar’ best for this purpose — this is where my Zotero buttons are as well. Here’s how:
- Right-click the quick access toolbar, choose ‘Customize Quick Access Toolbar’
- In the menu that appears, under “Choose commands from”, pick “Macros”. You’ll see your macro appear in the list.
- Select your macro (either version 1 or version 2) and click the Add >> button. With the up and down buttons on the right you can position it further; I like mine just next to the normal Save button.
- It’ll already work this way. If you’re a perfectionist like me, select your macro in the right column, click ‘Modify…’ and select an icon you like.
Voilá! You have your one-click “Save to PDF” button in Word.