none
Can I Run a VBA Script in pre-Word 2013 and Convert all PDF Files to Word Documents? RRS feed

  • Question

  • I have a VBA script that converts all PDF files in a folder to Word Documents, but apparently it ONLY works in Word 2013.  Is there anything out there that will convert all PDF files in a folder to Word documents.  I'd like to do this with a VBA script, which runs in Word, or a free 3rdparty utility.  If I have to pay, so be it, but I'd like to do this for free, if possible.  I need it in pre-2013 because people at my firm use Office 2010.  I have 2013 on my personal laptop, but no one at my firm has it yet.

    Thanks!!


    Knowledge is the only thing that I can give you, and still retain, and we are both better off for it.

    Wednesday, August 12, 2015 2:44 AM

Answers

  • To do this in Word versions prior to 2013, you'd need to automate a 3rd-party App such as Adobe Acrobat Pro that has an object model accessible to VBA. Adobe Acrobat Pro 8 is available as a free download.

    Cheers
    Paul Edstein
    [MS MVP - Word]


    • Edited by macropodMVP Wednesday, August 12, 2015 5:37 AM
    • Marked as answer by ryguy72 Wednesday, August 12, 2015 1:32 PM
    Wednesday, August 12, 2015 5:37 AM
  • For the benefit of others, you can download 2 sample Excel files from here.

    http://www.myengineeringworld.net/2013/03/vba-macro-to-convert-pdf-files-into.html

    That will allow you to convert your PDF files into a number of different formats, such as .doc, .txt, .xml, and all kinds of other things.  That is 100% free.  The only thing you need is Adobe Acrobat.  You can get a 30-day trial from here.

    https://helpx.adobe.com/acrobat/kb/acrobat-8-9-product-downloads.html

    I downloaded and tested everything and it all worked perfect!!  I probably won't keep the Adobe Acrobat installed when the trial ends, but it does work really well!!

    If you have Word 2013 and you want to convert all PDF files in a folder to .docx files, just run this VBA script.

    Sub convertToWord()
       Dim MyObj As Object, MySource As Object, file As Variant
       file = Dir("D:\OfficeDev\Word\201505\Pdf\" & "*.pdf") 'pdf path
       Do While (file <> "")
       ChangeFileOpenDirectory "D:\OfficeDev\Word\201505\Pdf\" 
              Documents.Open FileName:=file, ConfirmConversions:=False, ReadOnly:= _
            False, AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:= _
            "", Revert:=False, WritePasswordDocument:="", WritePasswordTemplate:="", _
            Format:=wdOpenFormatAuto, XMLTransform:=""
        ChangeFileOpenDirectory "D:\OfficeDev\Word\201505\Pdf\Word"'path for saving word
        ActiveDocument.SaveAs2 FileName:=Replace(file, ".pdf", ".docx"), FileFormat:=wdFormatXMLDocument _
            , LockComments:=False, Password:="", AddToRecentFiles:=True, _
            WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
             SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _
            False, CompatibilityMode:=15
        ActiveDocument.Close
         file = Dir
       Loop
    End Sub
    


    Knowledge is the only thing that I can give you, and still retain, and we are both better off for it.

    Wednesday, August 12, 2015 3:18 PM

All replies

  • To do this in Word versions prior to 2013, you'd need to automate a 3rd-party App such as Adobe Acrobat Pro that has an object model accessible to VBA. Adobe Acrobat Pro 8 is available as a free download.

    Cheers
    Paul Edstein
    [MS MVP - Word]


    • Edited by macropodMVP Wednesday, August 12, 2015 5:37 AM
    • Marked as answer by ryguy72 Wednesday, August 12, 2015 1:32 PM
    Wednesday, August 12, 2015 5:37 AM
  • Thanks for the info.

    Very helpful.


    Knowledge is the only thing that I can give you, and still retain, and we are both better off for it.

    Wednesday, August 12, 2015 1:32 PM
  • For the benefit of others, you can download 2 sample Excel files from here.

    http://www.myengineeringworld.net/2013/03/vba-macro-to-convert-pdf-files-into.html

    That will allow you to convert your PDF files into a number of different formats, such as .doc, .txt, .xml, and all kinds of other things.  That is 100% free.  The only thing you need is Adobe Acrobat.  You can get a 30-day trial from here.

    https://helpx.adobe.com/acrobat/kb/acrobat-8-9-product-downloads.html

    I downloaded and tested everything and it all worked perfect!!  I probably won't keep the Adobe Acrobat installed when the trial ends, but it does work really well!!

    If you have Word 2013 and you want to convert all PDF files in a folder to .docx files, just run this VBA script.

    Sub convertToWord()
       Dim MyObj As Object, MySource As Object, file As Variant
       file = Dir("D:\OfficeDev\Word\201505\Pdf\" & "*.pdf") 'pdf path
       Do While (file <> "")
       ChangeFileOpenDirectory "D:\OfficeDev\Word\201505\Pdf\" 
              Documents.Open FileName:=file, ConfirmConversions:=False, ReadOnly:= _
            False, AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:= _
            "", Revert:=False, WritePasswordDocument:="", WritePasswordTemplate:="", _
            Format:=wdOpenFormatAuto, XMLTransform:=""
        ChangeFileOpenDirectory "D:\OfficeDev\Word\201505\Pdf\Word"'path for saving word
        ActiveDocument.SaveAs2 FileName:=Replace(file, ".pdf", ".docx"), FileFormat:=wdFormatXMLDocument _
            , LockComments:=False, Password:="", AddToRecentFiles:=True, _
            WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
             SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _
            False, CompatibilityMode:=15
        ActiveDocument.Close
         file = Dir
       Loop
    End Sub
    


    Knowledge is the only thing that I can give you, and still retain, and we are both better off for it.

    Wednesday, August 12, 2015 3:18 PM