Convert Word Documents from a folder to PDF Files

Convert Word Documents from a folder to PDF Files


Well, Here I have a folder with Word document as shown below, and I want to convert all the document files to pdf files.

To Convert all word document from a folder to pdf files, I have created another document by the name - "Word Macro".

Now we need to activate the Developer Tab and Write one VBA code.

To activate Developer Tab - we need to click on

File --> Options --> Customize Ribbon --> Click on Developer Tab under Main Tab section.

You will see Developer Tab added onto your Ribbon.

Click on your Developer Tab -- > Click on Visual Basic, you will see

Right Clik on Reference and Insert on Module

You will see one code area window on your Right pane.

On the coding area, you need to write down this code and save the file. as

Word Macro Enabled Document (8.docm)

Sub ConvertWordsToPdfs()

'Updated by Extendoffice 20181123

Dim xIndex As String

Dim xDlg As FileDialog

Dim xFolder As Variant

Dim xNewName As String

Dim xFileName As String

Set xDlg = Application.FileDialog(msoFileDialogFolderPicker)

If xDlg.Show <> -1 Then Exit Sub

xFolder = xDlg.SelectedItems(1) + "\"

xFileName = Dir(xFolder & "*.*", vbNormal)

While xFileName <> ""

If ((Right(xFileName, 4)) <> ".doc" Or Right(xFileName, 4) <> ".docx") Then

xIndex = InStr(xFileName, ".") + 1

xNewName = Replace(xFileName, Mid(xFileName, xIndex), "pdf")

Documents.Open FileName:=xFolder & xFileName, _

ConfirmConversions:=False, ReadOnly:=False, AddToRecentFiles:=False, _

PasswordDocument:="", PasswordTemplate:="", Revert:=False, _

WritePasswordDocument:="", WritePasswordTemplate:="", Format:= _

wdOpenFormatAuto, XMLTransform:=""

ActiveDocument.ExportAsFixedFormat OutputFileName:=xFolder & xNewName, _

ExportFormat:=wdExportFormatPDF, OpenAfterExport:=False, OptimizeFor:= _

wdExportOptimizeForPrint, Range:=wdExportAllDocument, From:=1, To:=1, _

Item:=wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, _

CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _

BitmapMissingFonts:=True, UseISO19005_1:=False

ActiveDocument.Close

End If

xFileName = Dir()

Wend

End Sub

Close the Developer Window

To Run the Macro- Click on View Menu - Macro -- Run Macro

Choose your macro name and Click on Run, I will ask you to select the Folder from where you need to convent the doc files to pdf files. Choose the folder name and click on Ok.

Now check the folder, you will notice all your Word Document files is also saved as PDF files.

Please make a request to For additional details, follow our page. Please use [email protected] to contact us.


要查看或添加评论,请登录

Shiju Cherian的更多文章

社区洞察

其他会员也浏览了