'------------------------------------------------ ' 环境准备: ' 1.为运行本程序,应在“菜单->工程->部件”中添加“Microsoft Internet Controls” ' 2.并在“菜单->工程->引用”中添加“Microsoft HTML Object Library”和“Edanmo's OLE interfaces & functions v1.4” ' 3.请先建立文件"d:\1.html",内容为:<iframe application="yes" width=700 height=600 src="http://www.baidu.com" mce_src="http://www.baidu.com"></iframe> ' 4.Edanmo 's OLE interfaces & functions v1.4在有些机器可能没有,可以到这里下载:http://download.csdn.net/source/2652292 ' ' Author : sysdzw ' E-mail : sysdzw@163.com ' Bolg : http://hi.baidu.com/sysdzw ' QQ : 171977759 ' Date : 2010-4-6 '------------------------------------------------ Private Sub Form_Load() wb1.Navigate2 "d:\1.html" End Sub Private Sub wb1_DocumentComplete(ByVal pDisp As Object, URL As Variant) Debug.Print URL If URL = "http://www.baidu.com/" Then getFrames(wb1).Document.All("kw").Value = "谷歌" MsgBox getFrames(wb1).Document.All("kw").Value End If End Sub 'WB为要处理的webbrowser Private Function getFrames(ByVal WB As WebBrowser) As Object Dim pContainer As olelib.IOleContainer Dim pEnumerator As olelib.IEnumUnknown Dim pUnk As olelib.IUnknown Dim pBrowser As SHDocVwCtl.WebBrowser_V1 Set pContainer = WB.Object.Document If pContainer.EnumObjects(OLECONTF_EMBEDDINGS, pEnumerator) = 0 Then Set pContainer = Nothing Do While pEnumerator.Next(1, pUnk) = 0 Set pBrowser = pUnk If Err.Number = 0 Then Print "Frame: " & pBrowser.LocationURL If pBrowser.LocationURL = "http://www.baidu.com/" Then '可以在这里加条件判断得到指定的frame,基本可以根据url或者innerHTML中的某个关键字符 Set getFrames = pBrowser Exit Function End If End If Loop Set pEnumerator = Nothing End If End Function