我有以下代码在已打开的 Internet Explorer 中填写网络表单。
Sub L()
Dim IE As New SHDocVw.InternetExplorer
Dim SWs As New SHDocVw.ShellWindows
Dim PageTitle As String
On Error Resume Next
u = 1
'Looks at all windows in Windows
For Each IE In SWs
If (LCase(IE.FullName) Like "*iexplore*") = True Then
If u <> 1 Then
u = u + 1
End If
End If
PageTitle = IE.Document.Title
If InStr(PageTitle, "Home") Then
IE.Navigate "http://intranet.com/Webforms/TaskCreation.aspx"
Do 'Wait till the edit page is loaded.
Loop Until IE.ReadyState = READYSTATE_COMPLETE And Not IE.Busy
IE.Document.getElementById("Content_TEXT_ALPHA_COLUMN1").Value = "A"
IE.Document.getElementById("Content_TEXT_ALPHA_COLUMN2").Value = "B"
IE.Document.getElementById("Content_TEXT_ALPHA_COLUMN14").Value = "C"
IE.Document.Forms(0).Item("Content_ddlRegion").Value = "28"
IE.Document.Forms(0).Item("Content_ddlSubRegion").Value = "33"
IE.Document.Forms(0).Item("Content_ddlPriority").Value = "23"
IE.Document.Forms(0).Item("Content_ddlClientCode").Value = "37"
IE.Document.Forms(0).Item("Content_ddlCompanyCode").Value = "62"
IE.Document.Forms(0).Item("Content_DDL_COLUMN1").Value = "5978"
IE.Document.Forms(0).Item("Content_DDL_COLUMN2").Value = "5966"
IE.Document.Forms(0).Item("Content_ddlActivity").Focus
IE.Document.Forms(0).Item("Content_ddlActivity").Value = "13720"
IE.Document.Forms(0).Item("Content_ddlActivity").FireEvent ("onchange")
While IE.Busy
DoEvents
Wend
Application.Wait Now() + TimeValue("00:00:03")
IE.Document.Forms(0).Item("Content_ddlSubActivity").Value = "13735"
IE.Document.getElementById("Content_imgRequestRcvdDate").Click
IE.Visible = True
End If
Next IE
End Sub
这段代码昨天运行良好。它找到 pagetitle = Home 的 IE 并填写表单。
虽然我没有进行任何更改,但今天我收到了这个错误:当宏完成执行时,它会打开新的 Internet Explorer 窗口。有时它会打开一个,甚至四个窗口。
这是代码有问题吗?
你认为我应该删除 On error resume next 吗?
请帮我。
谢谢。