Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88054

Error in importing pdf files to excel using IE

$
0
0

I am trying to import some PDF files to excel using IE (open it in IE and copy-paste to excel ). My code is working for some pdf files. But for some it returns following error : "The remote server machine does not exist or is unavailable.."

Searched many forums to resolve this, but all leads to much complicated solutions which is beyond my coding skills (still am a newbie )... Please help.

My code:

Sub ImportPdf()
Dim FileName As String
Dim b2 As Workbook
Dim ie As Object
Dim np As Object
FileName="C:\somepdf.pdf"
Set b2 = ThisWorkbook
Set ie = CreateObject("InternetExplorer.Application")

ie.Visible = True

ie.navigate (FileName)

Application.Wait Now + TimeSerial(0, 0, 8)

Do While ie.ReadyState <> 4                          ''ERROR comes here.
    DoEvents
Loop
AppActivate ie                  

SendKeys "^(a)", True
Application.Wait Now + TimeSerial(0, 0, 2)
SendKeys "^(c)", True
Application.Wait Now + TimeSerial(0, 0, 2)
b2.Activate 
Application.ScreenUpdating = False
With Sheets(2).Activate
    Range("A1").Select
    ActiveSheet.Paste
End With
Sheets(1).Activate
Application.ScreenUpdating = True

ie.Quit

End Sub

The pdf files have tables, images and vary in sizes. Working file is small in size. if I remove the Do while loop, then error comes at AppActive ie line. Tried even removing that line, but error comes at ie.quit line.

Please also suggest if there is any easy method to import pdf to excel. (text only )


Viewing all articles
Browse latest Browse all 88054

Trending Articles