How To: Save Your Word Document as PDF with One Click (Using a Macro)

Save Your Word Document as PDF with One Click (Using a Macro)

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 How to Save Your Word Document as PDF with One Click (Using a Macro)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.

Step 1 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.

How to Save Your Word Document as PDF with One Click (Using a Macro)

How to Save Your Word Document as PDF with One Click (Using a Macro)

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.

Step 2 Coding our Macro

Be sure that "Normal"->"Modules"->"NewMacros" is selected in the upper left tree-structure (like in the image)

How to Save Your Word Document as PDF with One Click (Using a Macro)

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:

How to Save Your Word Document as PDF with One Click (Using a Macro)

Click "Save" in the upper left of the window and close it.

Step 3 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.

How to Save Your Word Document as PDF with One Click (Using a Macro)

Select "Macros" in the left drop-down list. There should be our Macro.

How to Save Your Word Document as PDF with One Click (Using a 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.

Step 4 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:

  1. Google your problem
  2. Google some more - there are solutions all over the Internet
  3. Leave a comment

Just updated your iPhone? You'll find new emoji, enhanced security, podcast transcripts, Apple Cash virtual numbers, and other useful features. There are even new additions hidden within Safari. Find out what's new and changed on your iPhone with the iOS 17.4 update.

6 Comments

This is so cool. Never knew a Macro can deal with it. I had some issues as the office versions as you mentioned were different. However, I dealt with it. All thanks to you. I am still wondering how to change the picture of my Macro, with the floppy disk picture that you got. I am using MS Office 2013. Thanks again.

There's a bug, it works incorrectly with files with dots in their names.
It should be
...InStrRev(ActiveDocument.Name, ".")) + "pdf"

Thank you very much. I particularly like the way that it does not prompt me for anything (even overwriting previous files). It just creates the PDF, which is just what I want. I use this macro in combination with PDFBinder (no affiliation). I use MSWord as a desktop publishing tool. It has advantages such as spell checking and familiarity, but a major disadvantage in that text and images placed on the same page tend to jump around. This is I think due to its lack of independent 'layers.' But MS word does provide an extra layer - the header/footer layer. If images are placed in the header/footer then they can be position independently of text in the body of the document. The problem is then that the header and footer layer is repeated on all pages. I have not experimented with attempting to create individual headers/footers for each page. I am not sure that that is possible. Instead I create one MSWord document per page. These I then convert to PDF so I have as many PDF files as there are pages in my document. Finally I search for pdf files in my manuscript folder area, drag them to PDFBinder and bind them all together in one long PDF document. This macro makes the process fast. Thank you.

I give it the red square icon which reminds me of the Adobe PDF icon but if there were a PDF icon to go with this how-to, it would be even cooler.

Alas I can't get it to work with Word 2007. I have installed the PDF thing. I installed the PDF extension after I created the macro. Does that make a difference? I will try that now.

No, alas, I still get the
Run-Time error 438
Object doesn't support this property or method.

I know I can save to PDF in the usual way, using save as, because I just did. That is a shame. It works great in 2010 though, but the first commenter says that the functionality was already there!? I did not know that, so I used this macro with great pleasure yesterday.

The macro works fine.
How can I add a pdf icon to alrrady existing symbols of the word 2010?

Share Your Thoughts

  • Hot
  • Latest