3 Macro Ways to Quickly Convert Your Word Documents into PDF Files

In this article, we will focus on providing you with 3 macros which you can use to quickly convert Word documents into pdf files.

In Word 2003, there is an icon on the menu bar. With a single click, users are able to trigger the “Save As” window instantly and save the document in pdf format.Save As PDF Icon

However, as you notice, the layout in Word 2010 changes a lot. And users have to click “File” tab then the “Save As” command to trigger the “Save As” window. Moreover, you have to manually choose the save type before hit “Save” button.Choose Save Type

With all these clicks, it’s not quick enough. Therefore, in this post, we’d love to exhibit the macro way to do that.

Macro 1: Trigger the “Save As” Window Quickly

  1. First and foremost, click “Developer” tab then click “Visual Basic” command to open VBA editor. Certainly, the 2 clicks have to be done when the “Developer” tab is displayed already. The alternative way is to press “Alt+ F11”.Click "Developer"->Click "Visual Basic"
  2. Secondly, click “Normal” project.
  3. Thirdly, click “Insert” and then choose “Module” on the list menu.
  4. Now double click on the module to show the editing area.Click "Normal"->Click "Insert"->Click "Module"
  5. Next, paste the following codes:
Sub TriggerSaveAsWindow()
  Dim dlgSaveAs As Dialog
 
  Set dlgSaveAs = Dialogs(wdDialogFileSaveAs)
  With dlgSaveAs
    .Format = wdFormatPDF
    .Show
    .Execute
  End With
End Sub
  1. Then click “Run”.Paste TriggerSaveAsWindow Macro->Click "Run"

Now there is the “Save As” window. And the save type is already in pdf. All left to do is to click on “Save” button. This macro enables you to change the file name if necessary.

Macro 2: Directly Save Word Files to PDF

In event some people want to save the file directly to pdf without revising the file name, here is the macro in need.

  1. First of all, repeat the first 4 steps above.
  2. Next, paste the following codes instead:
'Directly save Word file as Pdf and aumatically open it.
Sub DirectlySaveDocxToPdf()
  Dim objDoc As Document
 
  Set objDoc = ActiveDocument
  objDoc.ExportAsFixedFormat _
    OutputFileName:=Replace(objDoc.FullName, ".docx", ".pdf"), _
    ExportFormat:=wdExportFormatPDF, OpenAfterExport:=True, OptimizeFor:=wdExportOptimizeForPrint, _
    Range:=wdExportAllDocument, Item:=wdExportDocumentContent
End Sub
  1. Similarly, click “Run”.

Macro 3: Batch Convert Word Docx Files to PDFs

  1. Place all docx files in one folder first.
  2. Follow the above steps to have the editing area open.
  3. Then paste the bellowing macro:
Sub BatchConvertDocxToPDF()
  Dim objDoc As Document
  Dim strFile As String, strFolder As String
 
  'Initialization
  strFolder = "C:\Users\Test\Desktop\Test Files\"
  strFile = Dir(strFolder & "*.docx", vbNormal)
 
  'Precess each file in the file folder and convert them to pdf.
  While strFile <> ""
    Set objDoc = Documents.Open(FileName:=strFolder & strFile)
 
    objDoc.ExportAsFixedFormat _
      OutputFileName:=Replace(objDoc.FullName, ".docx", ".pdf"), _
      ExportFormat:=wdExportFormatPDF, OpenAfterExport:=False, OptimizeFor:=wdExportOptimizeForPrint, _
      Range:=wdExportAllDocument, Item:=wdExportDocumentContent
 
    objDoc.Close
    strFile = Dir()
  Wend
End Sub
  1. Never forget to click “Run” button.

Note: In codes “strFolder = “C:\Users\Test\Desktop\Test Files\””, the ““C:\Users\Test\Desktop\Test Files\”” is the file path of the folder. Remember to change it accordingly.

After running this macro, pdfs will be saved in the same folder where Word documents stay.Effect

Secure Files as You Can

There are preventive measures and also post-disaster actions to salvage damaged files. If you keep backing up your files on a regular basis, to get back the original file is just a piece of cake. The truth is few people can stick to their backup plan, hence increasing the risk of losing valuable data. Under such circumstances, it’s time to resort to an advanced Word document corruption fix tool.

Author Introduction:

Vera Chen is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including damaged Excel xlsx fix and pdf repair software products. For more information visit www.datanumen.com

2 responses to “3 Macro Ways to Quickly Convert Your Word Documents into PDF Files”

  1. Ahaa, its fastidious dialogue on the topic of this piece of writing here at this webpage, I have read all that, so at this time me also commenting here.

Leave a Reply

Your email address will not be published. Required fields are marked *