我在自动化现有的 IE 窗口时遇到错误。错误是
“对象变量或未设置块变量”代码是
Sub accessExistingIEBrowser()
boolWindowFound = False
Set objShell = CreateObject("Shell.Application")
WinCount = objShell.Windows.Count
For winNo = 0 To (WinCount - 1)
strURL = objShell.Windows(winNo).document.Location
strTitle = objShell.Windows(winNo).document.Title
If strTitle Like "Sample Form" Then
Set IE = objShell.Windows(winNo)
boolWindowFound = True
Exit For
Else
End If
Next
If boolWindowFound Then
Set doc = IE.document
doc.getElementsByName("fname")(0).Value = "test"
End If
End Sub