"SendKeys" command does not work

KhallP

Board Regular
Joined
Mar 30, 2021
Messages
157
Office Version
  1. 2016
Platform
  1. Windows
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
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
if you expect simple text try:

VBA Code:
.Paste
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,906
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top