I created a macro that opens a PDF file, inside that same file the macro uses the "SendKeys" command to select how you want to view the page and then double-click Esc to exit the menu and move the mouse to a certain point in da page, the problem is that when the program executes the second command of the "SendKeys" (Crtl + A) the program does not select everything and much less pastes the file data in the specified spreadsheet, to finish the program gives an error in the line " .PasteSpecial Format:="Text"
VBA Code:
Public Declare PtrSafe Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
Public Declare PtrSafe Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Public Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Sub pdf_To_Excel_Adobe()
Dim myworksheet As Worksheet, adobeReaderPath As String, pathAndFileName As String, shellPathName As String
Set myworksheet = ActiveWorkbook.Sheets("Teste")
adobeReaderPath = "C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe"
pathAndFileName = "D:\Users\AFCALME\Documents\Axis _ A8.1 _ 17.06.2021.pdf"
shellPathName = adobeReaderPath & " """ & pathAndFileName & """"
Call Shell( _
pathname:=shellPathName, _
windowstyle:=vbNormalFocus)
Sleep 1000
SendKeys "%vpc"
Sleep 1000
SendKeys "{ESC}"
Sleep 500
SendKeys "{ESC}"
SetCursorPos 500, 900
Sleep 1000
SendKeys "^a"
SendKeys "^c"
Sleep 1000
With myworksheet
.Range("B4").Select
.PasteSpecial Format:="Text"
End With
Call Shell("TaskKill /F /IM AcroRd32.exe", vbHide)
End Sub