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.
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.
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
- 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”.
- Secondly, click “Normal” project.
- Thirdly, click “Insert” and then choose “Module” on the list menu.
- Now double click on the module to show the editing area.
- 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
- Then 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.
- First of all, repeat the first 4 steps above.
- 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
- Similarly, click “Run”.
Macro 3: Batch Convert Word Docx Files to PDFs
- Place all docx files in one folder first.
- Follow the above steps to have the editing area open.
- 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
- 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.
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
Leave a Reply