2016-11-17 72 views
1

问题:我目前遇到了一些问题,关闭一个没有内容的“过早”互联网窗口。退出错误Internet Explorer窗口

prematured window

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

测试完成:

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. 当我返回每个计数窗口的位置或标题时,在尝试返回“提前”窗口的位置或标题时出现错误
  3. 两个循环我试图在这一端运行没有工作

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

+0

你什么错误,在哪里(哪一行代码)? – dee

+0

当我尝试msgBox这个页面的标题它不起作用,错误描述返回_Automation错误,未指定错误_ – Seb

回答

1

您的问题中的图像页面看起来很奇怪,没有位置,没有标题。试试下面的代码,但上线Set doc = ie.document设置断点,并检查是否docNothing等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 
+0

我试过了。正如你计划的那样,它是在Set doc = ie.document这一行中,当我们经历的那个“过早”窗口时代码会被破坏。返回的错误与上面提到的相同。这很奇怪,因为这个页面可以被统计,所以它以某种方式被识别,但是因为没有链接被链接,所以似乎不可能选择它。同样在我的测试代码中,我可以发现哪个窗口是“不成熟”的窗口,然后如果我尝试退出它,它实际上会退出计数器之后的窗口。 '设置page_foireuse = objShell.Windows(5) page_foireuse.Quit' – Seb

+0

好吧,这是一个耻辱,我设法找到错误,并避免在这个“过早”的网页上打开。然后关闭它仍然是一个谜。不幸的是,由于这个网页来自内部网,很难给你一个可访问的例子来与之联系,谢谢你的支持! – Seb

+0

不客气,祝你好运! :) – dee