Private Sub WebBrowser1_Document(ByValpDisp As Object, URL As Variant) If Not (pDisp Is WebBrowser1.Object) Then Exit Sub 在网上找的判断网页是否完全打开全是以WebBrowser1_Document开头,但是我要的是自动把EXCELL表中的数据一个一个的填写上去,需要循环,并且要中间还要不断进入新的页面,我想能不能找个别的方法进行判断??
换一个来,大家看下可否?
Private Sub Command1_Click()
Dim ex As Object
Dim wb As Object
Dim sh As Object
Dim Doc as object
dim i as integer
Set ex = CreateObject("Excel.Application")
Set wb = ex.Workbooks.Open("c:\1.xls")
Set sh = wb.Sheets(1)
FOR i=2 to 200
Webbrowser1.Navigate "http://192.168.1.2" '打开需要的网页
Do While WebBrowser1.IsBusy
Application.DoEvents() '等待网页完全打开
Set Doc = WebBrowser1.Document
Doc("name").click ‘点一个按钮
Do While WebBrowser1.IsBusy
Application.DoEvents() '再等待网页完全打开
Doc("work")=sh.cells(i,2)
Doc("end").click
next
ex.Visible = True
Set ex = Nothing
Set wb = Nothing
Set sh = Nothing
end sub
我这样写中不?
Private Sub WebBrowser1_Document(ByValpDisp As Object, URL As Variant)
'打开网页1 '再打开EXCELL
FOR i=1 to 300
If Not (pDisp Is WebBrowser1.Object) Then
For I = 1 To objDoc.All.Length - 1
If objDoc.All(I).Name = "username" Then
objDoc.All(I).Value = sh.cells(i,2) ‘填数据与点击
....................end if
'打开网页2
If Not (pDisp Is WebBrowser1.Object) Then
For I = 1 To objDoc.All.Length - 1
If objDoc.All(I).Name = "username1" Then
objDoc.All(I).Value = sh.cells(i,3)
。。。。。。。end if
NEXT
Dim doc As Object
Dim i As Object
Dim strHtml As String
on error resume next
Set doc = WebBrowser1.Document
For Each i In doc.All
strHtml = strHtml & Chr(13) & i.innertext
Next
getWebContent = strHtml
If InStr(getWebContent, "成功") > 0 Then
'自己的操作
end if