【发布时间】:2021-04-15 16:28:42
【问题描述】:
我在自动化现有 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
【问题讨论】:
-
您假设每个窗口都有一个非空的
document。事实并非如此。
标签: excel vba automation excel-automation ie-automation