In this article, we're going to create an additional button in our Word toolbar which creates a PDF file of our loaded file with one simple click. We are going to use the function to create Macros, which are little 'programs' in Office applications. The Macro we are going to write will literally save the file as PDF in the same directory and with the same filename as the opened document. The image on the right is what it will look like.
We will modify our normal.dot Word-Template to include a VBA-Macro, which saves our file as PDF.
So, let's get started!
Note
- This article uses German interfaces, but the screenshots should be clear enough for all languages.
Open Word and the VBA window
Open Microsoft Office Word.
Note
- This tutorial is based on Microsoft Office Professional Plus 2010, but works with other versions, as well. For Office 2007 you'll need the PDF extension.
Open the VBA menu by selecting the "Views" and selecting "Macros" -> "View Macros". All this can also be done by holding ALT and pressing F K M. If you are not using Word 2010, try this.
Create a new Macro: Enter a name for our Macro - let's say "PDF" - and click on "Create". The name should appear in the list below. Click on "Edit" to open the coding window of our project.
Coding our Macro
Be sure that "Normal"->"Modules"->"NewMacros" is selected in the upper left tree-structure (like in the image)
These two lines of VBA-Code should already be there:
Sub PDF()
End Sub
Add the following lines in-between those two predefined function lines:
If InStr(1, ActiveDocument.Name, ".") = 0 Then
MsgBox "File has to be saved first!"
Exit Sub
End If
ActiveDocument.SaveAs2 Replace(ActiveDocument.FullName, ActiveDocument.Name, "") + Mid(ActiveDocument.Name, 1, InStr(1, ActiveDocument.Name, ".") - 1) + ".pdf", Word.WdSaveFormat.wdFormatPDF
It should look like this now:
Click "Save" in the upper left of the window and close it.
Creating a new button for our Macro
So, this is also different in all the Office versions. But it's common that you have to right-click on your toolbar / ribbon and select the "Edit Toolbar" item.
Select "Macros" in the left drop-down list. There should be our Macro.
Open "View" in the tree-structure on the right and click "Create Group". You can edit the properties with the context menu (right-click). Enter something like "Macro Shortcuts".
Select the Macro (on the left) and the new group (on the right) and click "Add" (top button in the middle).
After adding rename our Macro (on the right side - right-click) to something you like. I'd say "Export to PDF".
Now close Word.
You're done!
Now on any new document - after you saved it - clicking this button will instantly save your file as a PDF. No more "Save As" dialogs and adventures through file type menus.
I know this is a bit tricky because of the differences in the details of the Office Versions (e.g. Ribbon and non-Ribbon UI). If you're stuck at any point feel free to:
- Google your problem
- Google some more - there are solutions all over the Internet
- Leave a comment
Comments
No Comments Exist
Be the first, drop a comment!