I would like to batch convert PDF files to Excel with this code:
Sub JobPackconverter()
Dim PDFFol As String, PDFout As String, Targetdir As String
Dim pdf_path As String, excel_path As String
PDFFol = GetFolder
PDFout = "Converted"
Targetdir = PDFFol & Application.PathSeparator & PDFout
If Not FolderExists(Targetdir) Then
MkDir Targetdir
End If
ThisWorkbook.Sheets("Sheet1").Range("C2").Value = PDFFol
ThisWorkbook.Sheets("Sheet1").Range("C3").Value = PDFFol & "" & PDFout
pdf_path = ThisWorkbook.Sheets("Sheet1").Range("C2")
excel_path = ThisWorkbook.Sheets("Sheet1").Range("C3")
Dim fso As New FileSystemObject
Dim fo As Folder
Dim f As file
Set fo = fso.GetFolder(pdf_path)
Dim wa As Object
Dim doc As Object
Dim wr As Object
Set wa = CreateObject("word.application")
wa.Visible = True
Dim nwb As Workbook
Dim nsh As Workbook
For Each f In fo.Files
Set doc = wa.Documents.Open(f.path, False, Format:="PDF Files")
Set wr = doc.Paragraphs(1).Range
wr.WholeStory
Set nwb = Workbooks.Add
Set nsh = nwb.Sheets(1)
wr.Copy
nsh.Paste
nwb.SaveAs (excel_path & Replace(f.Name, ".pdf", ".xlsx"))
doc.Close False
nwb.Close False
Next
wa.Quit
End Sub
Unfortunately the error below doesn’t allow me to do this.
Is there some way to have it working?
5