【问题标题】:Quit error Internet Explorer Window退出错误 Internet Explorer 窗口
【发布时间】:2016-11-17 14:02:38
【问题描述】:

问题:我目前在关闭“过早”的互联网窗口时遇到了一些问题,该窗口还没有内容。

基本上,如果这个“过早”窗口打开,我的宏无法选择我感兴趣的窗口,但是只要我手动关闭这个“过早”窗口,我就可以正确运行我的代码。 它的来源来自一个小错误,它以某种方式打开它,但除了显示该窗口不会影响其余代码。

测试完成:

Dim Widow As Object, page_foireuse As SHDocVw.InternetExplorer
Dim objShell As Object
Set objShell = CreateObject("Shell.Application")

     MsgBox objShell.Windows.Count
'    MsgBox objShell.Windows(0).document.Title
'    MsgBox objShell.Windows(1).document.Title
'    MsgBox objShell.Windows(2).document.Title
'    MsgBox objShell.Windows(3).document.Title
'    MsgBox objShell.Windows(4).document.Title
'    MsgBox objShell.Windows(5).document.Title
'    MsgBox objShell.Windows(6).document.Title


'For Each Widow In objShell.Windows
'    If Widow.document.Title Is Nothing Then ' this doesn't work
'        Set page_foireuse = Widow
'    End If
'Next

'
'If objShell.Windows(5).document.Title Is Nothing Then
'End If
        Set page_foireuse = objShell.Windows(5)
    page_foireuse.Quit

 MsgBox objShell.Windows.Count

目前的结果:

  1. 当我计算shell中的窗口数量时,这个“过早”的窗口也被计算在内
  2. 当我返回每个计数窗口的位置或标题时,尝试返回“过早”窗口的位置或标题时出现错误
    1. 我尝试在这端运行的两个循环不起作用

所以我的问题是:如何通过宏关闭这个“过早的”窗口?

【问题讨论】:

  • 你得到什么错误,在哪里(哪一行代码)?
  • 当我尝试 msgBox 这个页面的标题它不起作用并且错误描述返回 Automation error , unspecified error

标签: windows vba internet-explorer


【解决方案1】:

您问题中图片上的页面看起来很奇怪,没有位置,没有标题。试试下面的代码,但是在Set doc = ie.document这一行设置断点并检查doc是否不是Nothing等HTH

' Add reference to Microsoft Internet Controls (SHDocVw)
' Add reference to Microsoft HTML Object Library
' Add reference to Microsoft Shell Controls And Automation

Dim ie As SHDocVw.WebBrowser
Dim doc As HTMLDocument
Dim shellApp As Shell32.Shell
Dim windows As SHDocVw.ShellWindows
Dim window

Set shellApp = New Shell
Set windows = shellApp.windows

For Each window In windows
    If Not UCase(window.FullName) Like "*IEXPLORE.EXE" Then GoTo continue
    Set ie = window
    Set doc = ie.document
    If doc.Title = "" Then
        ie.Quit
        Exit For
    End If
continue:
Next window

【讨论】:

  • 我试过了。正如您所计划的,当我们通过“过早”窗口时,代码在Set doc = ie.document 行中中断。返回的错误与我上面提到的相同。这很奇怪,因为这个页面可以被计数,所以它以某种方式被识别,但由于没有链接任何路径,似乎不可能选择它。同样在我的测试代码中,我可以发现哪个窗口是“过早的”窗口,然后如果我尝试退出它,它实际上会在计数中退出它后面的窗口。 Set page_foireuse = objShell.Windows(5) page_foireuse.Quit
  • 好的,很遗憾,我设法找到了错误并避免在这个“过早”的网页上打开。然后关闭它仍然是一个谜。不幸的是,由于此网页来自 Intranet,因此很难为您提供一个易于理解的示例,但感谢您的支持!
猜你喜欢
  • 2012-01-25
  • 2021-08-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-10-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多