Using an IE browser with Visual Basic

后端 未结 1 1940
猫巷女王i
猫巷女王i 2021-01-21 22:59

Struggling to find a solution to this one. From Visual Basic (VBA in Excel more specifically) I\'m able to call an Internet Explorer window by title using

AppAc         


        
相关标签:
1条回答
  • 2021-01-21 23:50

    You could try something like this, drawing heavily on reusing Internet Explorer COM Automation Object to identify an instance of IE with then specific web page active that you are looking for.

    Change
    strURL = "http://www.theage.com.au/"
    to

    "My Page Title - Windows Internet Explorer" as necessary

    VBA

    Sub Test()
    Dim ShellApp As Object
    Dim ShellWindows As Object
    Dim IEObject  As Object
    Dim strURL As String
    strURL = "http://www.theage.com.au/"
    Set ShellApp = CreateObject("Shell.Application")
    Set ShellWindows = ShellApp.Windows()
    Dim i
    For i = 0 To ShellWindows.Count - 1
        If InStr(ShellWindows.Item(i).FullName, "iexplore.exe") <> 0 Then
            If ShellWindows.Item(i).LocationURL = strURL Then
                Set IEObject = ShellWindows.Item(i)
                MsgBox "IE instance with " & strURL & " found"
                Exit For
            End If
        End If
    Next
    End Sub
    
    0 讨论(0)
提交回复
热议问题