fire746
Gebruiker
- Lid geworden
- 12 jul 2012
- Berichten
- 57
Hallo ik wil onderstaande vba code gebruiken om met een macro meerdere PDF files om te zetten naar excel.
Maar deze code geeft een fout code, toegevoegd middels 2 foto's. Wie kan mij hiermee helpen om dit werkend te krijgen, ik zie het niet.


Maar deze code geeft een fout code, toegevoegd middels 2 foto's. Wie kan mij hiermee helpen om dit werkend te krijgen, ik zie het niet.
Code:
Option Explicit
Option Compare Text
Sub pdfExcelMacro()
Dim pdf_path As String
Dim excel_path As String
Dim filename As String
Dim x1workbook As Workbook
Dim x1worksheet As Worksheet
Dim wordApp As New Word.Application
Dim wordDoc As Word.Document
Dim wordRange As Word.Range
'file path***********it should be exactly same. look at slash \
pdf_path " ThisWorkbook.path & " \ pdf_files \ ""
excel_path " ThisWorkBook.path & " \ excel_files \ ""
'*********************************************************
Application.ScreenUpdating = False
Application.StatusBar = False
wordApp.Visible = True
filename VBA.Dir(pdfpath)
While filename <> ""
If filename Like "*.pdf" Then
Application.CutCopyMode " False"
'here we open word
Set wordDoc = wordApp.Documents.Open(pdfpath & filename, Format:="PDF Files", ReadOnly:=True)
Set wordRange = wordDoc.Paragraphs(1).Range
wordRange.WholeStory
Set x1workbook = Excel.Workbooks.Add
Set x1worksheet = xlWorksheet.Sheets(1)
'here we copy the word range
wordRange.Copy
'now pasting word data in excel
x1worksheet.PasteSpecial Format:="Text", linl:=False, DisplayAsIcon:=False
x1workbook.SaveAs (excelpath & VBA.Replace(filename, ".pdf", "xlsx"))
x1workbook.Close False
wordDoc.Close False
End If
filename = VBA.Dir()
Wend
Application.CutCopyMode = False
Application.StatusBar = False
Application.ScreenUpdating = False
MsgBox "Done", vbInformation
'to display folder
Call Shell("explorer.exe " & excelpath, vbNormalFocus)
End Sub

