Quantcast
Channel: General Office Development forum
Viewing all articles
Browse latest Browse all 2257

vba Activate a Tab in Internet Explorer

$
0
0

Hi,

Using code like this:

    Function GetIE(sAddress As String) As Object
    ' Find an IE window with a matching (partial) URL.  Assumes no frames.
    '
        Dim objShell As Object, objShellWindows As Object, o As Object
        Dim retVal As Object, sURL As String
   
        Set retVal = Nothing
        Set objShell = CreateObject("Shell.Application")
        Set objShellWindows = objShell.Windows
   
        For Each o In objShellWindows
            sURL = ""
            On Error Resume Next
            sURL = o.Document.Location
            On Error GoTo 0
            If sURL <> "" Then
                If sURL Like sAddress & "*" Then
                  Set retVal = o
                  Exit For
                End If
            End If
        Next o
   
        Set GetIE = retVal
    End Function

we can find an existing instance of IE with a certain page loaded. 
We can then use the following declarations:

    Public Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long

    Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
    Private Const SW_SHOWNORMAL = 1
    Private Const SW_MAXIMIZE = 3
    Private Const SW_SHOW = 5
    Private Const SW_MINIMIZE = 6
    Private Const SW_RESTORE = 9

    Private Declare Function IsIconic Lib "user32.dll" (ByVal hwnd As Long) As Long

with the following code, to check if IE is minimized:

    If CBool(IsIconic(IE.hwnd)) Then    'if window is minimized...
        ShowWindow IE.hwnd, SW_RESTORE  'restore the window
    End If
    
and set the IE window to be in focus:

    SetForegroundWindow IE.hwnd 'activeate the IE window

but if the captured IE object represents an inactive tab, the above only brings the IE main window into focus -how do I activate the internet explorer tab that belongs to the IE object?

I've looked everywhere and can't find anything.  Would we have to use an IAccessible object?

Thanks in advance.

Cheers
Rich


Viewing all articles
Browse latest Browse all 2257

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>