使用SendKeys(“ ^ a”)复制网站数据并在Excel中粘贴

时间:2019-07-14 10:55:43

标签: excel vba pdf sendkeys pdf-scraping

我有可以浏览网页的VBA代码,但Sendkeys“ ^ a”,“ ^ c”无法正常工作。尝试了多次但没有运气。

请提出建议。

使用此代码:

Set DestinationWorksheet = ActiveSheet
Dim myURL As String

    Dim HTMLdoc As HTMLDocument
    Dim TDelements As IHTMLElementCollection
    Dim TDelement As HTMLTableCell
    Dim r As Long
    Dim date_now As String
    Set ie = CreateObject("InternetExplorer.Application")
    myURL = "https://www.annauniv.edu/pdf/pdf19.pdf"
    With ie
        .navigate myURL
        .Visible = True
 Do While ie.busy
        Application.Wait DateAdd("s", 1, Now)
    Loop
            Set HTMLdoc = .document
        End With

      SendKeys "^a"                                                                 ' Select all in PDF document
      SendKeys "^c"                                                                 ' Copy selected contents

      Application.Wait Now + TimeValue("00:00:02")                                  ' Wait a little to give clipboard time to copy (if huge contents)

      DoEvents

      SendKeys "^q"                                                                 ' Close PDF document

      Application.Wait Now + TimeValue("00:00:01")                                  ' Wait a little to give document time to close completely
      Application.Run "ActivateExcel", True                                         ' Re-activate Excel in case another application was activate when closing PDF Reader
      DoEvents

      Err.Clear
      DestinationWorksheet.Paste                                                    ' Paste PDF contents into worksheet

我希望将数据粘贴到excel的活动表中

0 个答案:

没有答案