给你个例子,就是打开本站的论坛,http://club.excelhome.net/, 然后点击打开Excel VBA程序开发版块,
Sub aa()
Dim IE As New InternetExplorer '引用 Microsoft Internet Controls 'shdocvw.dll
Dim oDoc As New MSHTML.HTMLDocument '引用 Microsoft HTML Object Library 'mshtml.dll
Dim x2 As Integer
Dim myrange As Range
IE.Visible = True
IE.Navigate URL:="http://club.excelhome.net/"
Do While IE.Busy Or (IE.ReadyState <> READYSTATE_COMPLETE)
DoEvents
Loop
Set oDoc = IE.Document
For x2 = 0 To oDoc.getElementsByTagName("a").Length - 1 '找到表格中当前行的相对应的图片,点击进入下层
If oDoc.getElementsByTagName("a").Item(x2).href = "http://club.excelhome.net/forum-2-1.html" Then
IE.Navigate URL:=oDoc.getElementsByTagName("a").Item(x2).href
Do While IE.Busy Or (IE.ReadyState <> READYSTATE_COMPLETE) '确保网页加载完成
DoEvents
Loop
Exit For '找到后,就退出循环
End If
Next x2
End Sub
要引用IE和HTML对象,