-2

我创建了一个宏,让我可以与网站交互并识别源中的某个按钮,并使用它将数据导出到 Excel 文件。下面是我的宏......我在下面发现的问题在评论中。如果需要进一步的规范,请告诉我。

 Sub Scrape1()
 Dim Browser As InternetExplorer
 Dim Document As HTMLDocument
 Dim Elements As IHTMLElementCollection
 Dim Element As IHTMLElement
 Dim excelElement As IHTMLElement
 Dim objElement As Object

 Set Browser = New InternetExplorer
 Browser.Visible = True
 Browser.navigate "http://www.site.com"

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

 Set Document = Browser.Document

 Set Elements = Document.getElementById("ctl31_ctl06_ctl04_ctl00_Menu").
 getElementsByTagName("a")

 For Each Element In Elements

 'The object I'm looking to use has an InnerText of "Excel"
 'set objElement as the Element with the InnerText of "Excel" so that I can say 
 objElement.Click

 Next Element

 Set Document = Nothing
 Set Browser = Nothing
 End Sub
4

1 回答 1

2
For Each Element In Elements
    'Debug.Print Element.innerText
    If Element.innerText = "Excel" Then 
        Element.Click
        Exit For
    End If

Next Element
于 2013-10-22T23:52:56.297 回答