Share via

Need to batch convert Word to PDF files ...

Anonymous
2016-08-30T15:28:22+00:00

Hi,

Is there anyway to convert or save (200+) Microsoft Word 2016 files on my PC to PDF? Or perhaps someone has written a macro or javascript that can process multiple Word files to do this repetitive task?

Thanks in advance for your assistance.

-Greg

Microsoft 365 and Office | Word | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

12 answers

Sort by: Most helpful
  1. Anonymous
    2016-08-30T16:55:08+00:00

    Hi,

    Is there anyway to convert or save (200+) Microsoft Word 2016 files on my PC to PDF? Or perhaps someone has written a macro or javascript that can process multiple Word files to do this repetitive task?

    Thanks in advance for your assistance.

    -Greg

    After trolling this site I found my answer here after doing a few minor tweaks:

    http://answers.microsoft.com/en-us/office/forum/office_2007-word/is-it-possible-to-convert-a-batch-of-doc-files-to/8f5549be-8143-4f0a-8f82-06c855fcb092

    Sub SaveAllAsPDF()

    Dim strFilename As String

     Dim strDocName As String

     Dim strPath As String

     Dim oDoc As Document

     Dim fDialog As FileDialog

     Dim intPos As Integer

     Set fDialog = Application.FileDialog(msoFileDialogFolderPicker)

     With fDialog

         .Title = "Select folder and click OK"

         .AllowMultiSelect = False

         .InitialView = msoFileDialogViewList

         If .Show <> -1 Then

             MsgBox "Cancelled By User", , "List Folder Contents"

             Exit Sub

         End If

         strPath = fDialog.SelectedItems.Item(1)

         If Right(strPath, 1) <> "" Then strPath = strPath + ""

     End With

     If Documents.Count > 0 Then

         Documents.Close SaveChanges:=wdPromptToSaveChanges

     End If

     If Left(strPath, 1) = Chr(34) Then

         strPath = Mid(strPath, 2, Len(strPath) - 2)

     End If

     strFilename = Dir$(strPath & "*.doc")

     While Len(strFilename) <> 0

         Set oDoc = Documents.Open(strPath & strFilename)

         strDocName = ActiveDocument.FullName

         intPos = InStrRev(strDocName, ".")

         strDocName = Left(strDocName, intPos - 1)

    'This instruction converts to PDF 

           strDocName = strDocName & ".pdf"

         oDoc.SaveAs FileName:=strDocName, _

             FileFormat:=wdFormatPDF

         oDoc.Close SaveChanges:=wdDoNotSaveChanges

         strFilename = Dir$()

     Wend

     End Sub

    Regards,

    Greg

    100+ people found this answer helpful.
    0 comments No comments
  2. Anonymous
    2016-08-30T15:39:56+00:00

    FYI, if it's helpful, please find my version as a JPG image below:

    10+ people found this answer helpful.
    0 comments No comments
  3. Anonymous
    2016-10-09T08:05:59+00:00

    This does work very quickly. I need to find out how to save the metadata as wel in the pdf like title, subject tags etc. That is not saved. Is this something that can be in the macro as well? When saving manually from word to PDF these metadata (title, subject, keywords) are also not converted into the PDF properties. If you have Adobe Acrobat installed as a plugin in Word and using the plugin it automatically converts these properties correctly. So in a batch for hundreds of files, this is also important. 

    http://gov.texas.gov/files/disabilities/accessdocs/13-converttopdf.pdf

    10+ people found this answer helpful.
    0 comments No comments
  4. Anonymous
    2017-08-22T15:07:17+00:00

    Hi,

    Is there anyway to convert or save (200+) Microsoft Word 2016 files on my PC to PDF? Or perhaps someone has written a macro or javascript that can process multiple Word files to do this repetitive task?

    Thanks in advance for your assistance.

    -Greg

    After trolling this site I found my answer here after doing a few minor tweaks:

    http://answers.microsoft.com/en-us/office/forum/office_2007-word/is-it-possible-to-convert-a-batch-of-doc-files-to/8f5549be-8143-4f0a-8f82-06c855fcb092

    Sub SaveAllAsPDF()

    Dim strFilename As String

     Dim strDocName As String

     Dim strPath As String

     Dim oDoc As Document

     Dim fDialog As FileDialog

     Dim intPos As Integer

     Set fDialog = Application.FileDialog(msoFileDialogFolderPicker)

     With fDialog

         .Title = "Select folder and click OK"

         .AllowMultiSelect = False

         .InitialView = msoFileDialogViewList

         If .Show <> -1 Then

             MsgBox "Cancelled By User", , "List Folder Contents"

             Exit Sub

         End If

         strPath = fDialog.SelectedItems.Item(1)

         If Right(strPath, 1) <> "" Then strPath = strPath + ""

     End With

     If Documents.Count > 0 Then

         Documents.Close SaveChanges:=wdPromptToSaveChanges

     End If

     If Left(strPath, 1) = Chr(34) Then

         strPath = Mid(strPath, 2, Len(strPath) - 2)

     End If

     strFilename = Dir$(strPath & "*.doc")

     While Len(strFilename) <> 0

         Set oDoc = Documents.Open(strPath & strFilename)

         strDocName = ActiveDocument.FullName

         intPos = InStrRev(strDocName, ".")

         strDocName = Left(strDocName, intPos - 1)

    'This instruction converts to PDF 

           strDocName = strDocName & ".pdf"

         oDoc.SaveAs FileName:=strDocName, _

             FileFormat:=wdFormatPDF

            

         oDoc.Close SaveChanges:=wdDoNotSaveChanges

         strFilename = Dir$()

     Wend

     End Sub

    Regards,

    Greg

    Hello again,

    It seems, this automated project was such a success last year, I've been asked to repeat the process. However, this time around I need to merge individual word documents with Excel spreadsheets. For example, I am doing a test of 10 out of 140 Word documents called, YYYY_Reunion.docx where "YYYY" references a unique Class Year (i.e 1948, 1949, 1950,...2014, 2015 2016). For each Word document I have a matching Excel spreadsheet called, YYYY_Reunion.xlsx.

    What I need to know is how to modify this macro to perform mail merges for matching Word & Excel files? If so, I will also need to create Proof and Final versions. Each "Proof " will contain the first 2 records of the Excel spreadsheet and the "Final" includes all records.

    Thanks in advance for any help you can provide.

    Regards,

    Greg

    9 people found this answer helpful.
    0 comments No comments
  5. Anonymous
    2016-10-09T09:42:29+00:00

    If you use http://www.gmayor.com/document\_batch\_processes.htm   to do the file handling, the built-in process to Convert to PDF will retain the metadata you refer to (the PDF Creator option, if available does not).

    Note that the process to convert to PDF only works with the folder option set. For a single document it requests that you make the save manually. If you want to test with a single document, create a new folder and put a document in it and then run the process.

    7 people found this answer helpful.
    0 comments No comments