-2

我在自动化现有的 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
4

1 回答 1

-1

“对象变量或未设置块变量”意味着您在代码中的某处省略了Set语句。在这段代码的开头设置一个断点(F9),开始调试(F5)和单步(F8)通过你的代码,你会发现在哪里。

于 2021-01-10T15:29:29.293 回答