尝试执行Element.Click命令时如何解决运行时错误

时间:2019-04-30 00:33:45

标签: html excel vba web-scraping

我正在尝试运行一个宏,该宏单击IE网页以下载文件。运行宏时,我遇到Runtime Error 91: Object variable or with block variable not set出于安全目的删除了url字符串

突出显示的行是Element.Click我该如何解决

Sub Playthissub()

     Call Scrape("myurl") '' change the website here and execute this sub.

End Sub

 Sub Scrape(url As String)

     Dim Browser As InternetExplorer
     Dim Document As HTMLDocument
     Dim Elements As IHTMLElementCollection
     Dim Element As HTMLGenericElement

     Set Browser = New InternetExplorerMedium
     Browser.Visible = True
     Browser.Navigate url

     Do While Browser.Busy And Not Browser.readyState = READYSTATE_COMPLETE
         DoEvents
     Loop
     Set Document = Browser.Document

     Set Elements = Document.getElementsByTagName("navPipeline")

     Element.Click

     Browser.Quit
 End Sub

0 个答案:

没有答案