既に開いている Internet Explorer で Web フォームに入力する次のコードがあります。
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 ウィンドウが開きます。ときどき、1 つ、場合によっては 4 つのウィンドウが開きます。
これはコードに何か問題がありますか?
On error resume next を削除する必要があると思いますか?
私を助けてください。
ありがとう。