PDA

View Full Version : Copy the data from pdf to Excel VBA



zetus
10-16-2015, 05:07 AM
i run the click button, it prompt error. would anyone can help me to take a look and try to help me to solve the problem. thanks

actually, i want to perform an action, once a press the button, it can copy and paste all data in specifiied pdf file into excel worksheet. thanks

Sub update()


Dim acrobatID
Dim acrobatInvokeCmd As String
Dim acrobatLocation As String


Dim R As String
Dim DataObj As MSForms.DataObject


Set DataObj = New MSForms.DataObject


R = ""


strDocument = Application.GetOpenFilename("PDF Files,*.pdf,All Files,*.*", 1, "Open File", , False) ' get pdf document name
If Len(strDocument) < 6 Then Exit Sub

acrobatLocation = "C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe"
acrobatInvokeCmd = acrobatLocation & " " & strDocument
acrobatID = Shell(acrobatInvokeCmd, 1)


AppActivate acrobatID


Application.Wait Time + TimeSerial(0, 0, 1)
SendKeys "^a", True
Application.Wait Time + TimeSerial(0, 0, 1)
SendKeys "^c", True


DataObj.GetFromClipboard


If Not R = DataObj.GetText Then

S = DataObj.GetText
Cells(S).Value


End If


End Sub