简体   繁体   English

VBA中的Internet Explorer子窗口

[英]Internet Explorer child window in VBA

I have a VBA code that clicks a link on a IE page and a new window opens. 我有一个VBA代码,可单击IE页面上的链接并打开一个新窗口。 How can I get the elements of that child window? 如何获得该子窗口的元素?

I tried with Shell.application. 我尝试了Shell.application。 Are there any other methods? 还有其他方法吗?

Set objShell = CreateObject("shell.application")
IEcount= objShell.Windows.Count
 For x = 0 To iecount
    On Error Resume Next
    Debug.Print x, objShell.Windows(x).document.Location
 Next x

I got the window number and its URL but can't access the elements on the page. 我得到了窗口号及其URL,但是无法访问页面上的元素。

Look at the "if-then" statement I've inserted within your code. 查看我在您的代码中插入的“ if-then”语句。 You can use either the title or url to identify the child and set focus on it. 您可以使用标题或URL来标识子项并对其进行设置。 Once it has focus, you can get the elements of the child window. 一旦获得焦点,就可以获取子窗口的元素。

Set objShell = CreateObject("Shell.Application")
IE_count = objShell.Windows.Count
For x = 0 To (IE_count - 1)
    On Error Resume Next    ' sometimes more web pages are counted than are open
    my_url = objShell.Windows(x).Document.Location
    my_title = objShell.Windows(x).Document.Title

    If my_title Like "Something that identifies your child window" Then
        Set ie = objShell.Windows(x)
        Exit For
    Else
    End If
Next

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM