Using AppActivate and Sendkeys in VBA shell command

后端 未结 6 1018
一个人的身影
一个人的身影 2021-01-05 16:30

I want to switch back and forth between application with the shell command in VBA. I am using SendKeys to do stuff in process A then move to process B, then to process A the

6条回答
  •  渐次进展
    2021-01-05 16:51

    After hours of research on various forums, I could figure out that I wont be able to use Adobe library objects and functions with Adobe Reader. The only viable option left was to use Shell Commands to use "save as text" option available in the Adobe Reader's file menu. The shortcut key is Alt+f+a+x+s. I implemented these in the below code which worked perfectly, although I was required to insert delays in some steps.

    Sub SavePDFasText()
    Dim AdobeReaderPath As String
    Dim PdfFilePath As String
    Dim PDFid, NotepdId As Double
    
    AdobeReaderPath = "C:\Program Files\Adobe\Reader 10.0\Reader\AcroRd32.exe"
    PdfFilePath = "D:\PowerGenMacro\opm_11.pdf"
    PDFid = Shell(AdobeReaderPath & " " & PdfFilePath, vbNormalFocus)
    Application.Wait TimeSerial(Hour(Now()), Minute(Now()), Second(Now()) + 5)
    'Alt+f+a+x is required to save the pdf as text in the adobe reader
    SendKeys "%(FAX)", True
    Application.Wait TimeSerial(Hour(Now()), Minute(Now()), Second(Now()) + 2)
    SendKeys "%S", True
    SendKeys "^q", True
    
    End Sub
    

提交回复
热议问题