Batch convert pdf to docx with microsoft office

I do like the way how word converts pdf's to docx format. The layout is almost flawless (tables/footers/headers etc). I tried out a lot of tools but Microsoft Word does it very very good. Is there a way to batch convert a lot of pdf's to docx format with word? Some way of doing it with a command line utility or other way?

asked Oct 1, 2020 at 22:11 113 4 4 bronze badges

1 Answer 1

You can refer to the vba code below:

Option Explicit Sub other2docx() On Error Resume Next Dim sEveryFile As String,sSourcePath As String,sNewSavePath As String Dim CurDoc As Object sSourcePath = "E:\file location\" sEveryFile = Dir(sSourcePath &"*.pdf") Do While sEveryFile <> "" Set CurDoc = Documents.Open(sSourcePath & sEveryFile, , , , , , , , , , , msoFalse) CurDoc.Convert sNewSavePath = VBA.Strings.Replace(sSourcePath & sEveryFile, ".pdf", ".docx") CurDoc.SaveAs2 sNewSavePath, wdFormatDocumentDefault CurDoc.Close SaveChanges:=False sEveryFile = Dir Loop Set CurDoc = Nothing 

It is easy to report errors when converting pdf to docx, and sometimes it will make the word stuck, so you can only use the task manager to end the word. Pay attention to which PDF file is causing the stuck, and then move this PDF file to another folder, do not let Word convert this file again.

answered Oct 2, 2020 at 7:46 Binggo_ MSFT Binggo_ MSFT 894 5 5 silver badges 5 5 bronze badges

I have executed this is VB editor. Is there also a way to execute it from powershell or cmd? Also needed to add "End Sub" at the end as it VBE was giving errors.

Commented Oct 2, 2020 at 20:15 You could convert the code to vbscript and run it using cscript from either powershell or cmd.. Commented Oct 3, 2020 at 5:28

You must log in to answer this question.

Related

Hot Network Questions

Subscribe to RSS

Question feed

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

Site design / logo © 2024 Stack Exchange Inc; user contributions licensed under CC BY-SA . rev 2024.9.10.15036