Internet Explorer child window in VBA

回眸只為那壹抹淺笑 提交于 2020-01-05 16:41:25

问题


I have a VBA code that clicks a link on a IE page and a new window opens. How can I get the elements of that child window?

I tried with 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.


回答1:


Look at the "if-then" statement I've inserted within your code. You can use either the title or url to identify the child and set focus on it. 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


来源:https://stackoverflow.com/questions/22510407/internet-explorer-child-window-in-vba

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!