'Error when pasting in excel from pdf with SendKeys
I am trying to copy a whole pdf document into excel using the following code. The code works perfectly except for the paste part, when it gives me the following error:
"run time error 1004 pastespecial method of range class failed".
But it is really weird because after that, it will let me paste it manually into the excel, so the data is in the clipboard.
I have tried many different paste formulas but none of them are working. I do not know how to fix the error.
Thank you for your help. Find below the code that I am using
Dim varRetVal As Variant, PathToPDF As String, strCommand As String
PathToPDF = "C:\Users\takyar\Desktop\test1.pdf"
PathToPDF = pdf_file_FR
strCommand = "C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe " & PathToPDF
' Use Shell Function to open Adobe Acrobat Reader
varRetVal = Shell(strCommand, 1)
' wait
Application.Wait Now + TimeValue("00:00:05")
'First select all data of PDF file, next copy to clipboard
SendKeys "^a" 'select all data
SendKeys "^c" ' copy data
'Wait
Application.Wait Now + TimeValue("00:00:05")
'Close Acrobat Reader or PDF file
SendKeys "%{F4}"
' Wait
Application.Wait Now + TimeValue("00:00:02")
' Paste to added worksheet (PDFText)
SendKeys "^c"
'Range("A1").Select
Sheets.Add.Name = "FRpdfinfo"
Worksheets("FRpdfinfo").Select
ActiveSheet.Range("a1").PasteSpecial Paste:=xlPasteValuesAndNumberFormats, _
Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|