AppActivate Substitute for IE8

bgoldac

New Member
Joined
Sep 12, 2010
Messages
5
I recently upgraded to IE8 from IE6 and I have found that AppActivate no longer works in IE8. I am looking for a substitute for this piece of code which simply sets focus to the last open IE window.

Code:
Sub ActivateIE
 
AppActivate "Internet Explorer"
 
End Sub
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
If it helps, I'm not a complete novice to VBA so I'd be willing to investigate more complex solutions to this issue.

Thanks in advance!
 
Upvote 0
I post this response with a similar attitude ... I'm willing to put in the hours to get cool stuff done - but I'm probably not doing it the "right" way ... and I'm borrowing from a ton of other posts around the net...

Here's how I'm doing it now ... after the code I'll explain a few things I plan to do, and the known problems...

** Requires reference to Microsoft Internet Explorer (browse for SHDocVw.dll if you can't see it)
Code:
Public Declare Function SetForegroundWindow Lib "user32" (ByVal hWnd As Long) As Long
Public Declare Function ShowWindow& Lib "user32" (ByVal hWnd As Long, ByVal nCmdShow As Long)

'Declare constants (for API functions)
    Public Const SW_SHOWNORMAL As Long = 1
Private Sub cmdOpenLink_Click()
    Dim strSiteAddress As String
    Dim myIE As SHDocVw.InternetExplorer
    Dim Newsite As Object
    
    strFDRAddress = "http://www.google.com"
    
    Set myIE = GetOpenIEByURL(strSiteAddress)
    
    If Not myIE Is Nothing Then
        ShowWindow& myIE.hWnd, SW_SHOWNORMAL
        SetForegroundWindow myIE.hWnd
        myIE.Visible = True
    Else
        Set Newsite = CreateObject("InternetExplorer.application")
        Newsite.Navigate strSiteAddress
        Newsite.FullScreen = True
        Newsite.FullScreen = False
        Newsite.Visible = True
        ShowWindow Newsite.hWnd, SW_SHOWNORMAL
        SetForegroundWindow Newsite.hWnd
    End If
    
End Sub



'finds an open IE site by checking the URL
Function GetOpenIEByURL(ByVal i_URL As String) As SHDocVw.InternetExplorer
    Dim objShellWindows As New SHDocVw.ShellWindows

    'ignore errors when accessing the document property
    On Error Resume Next
    'loop over all Shell-Windows
    For Each GetOpenIEByURL In objShellWindows
        'if the document is of type HTMLDocument, it is an IE window
        If TypeName(GetOpenIEByURL.Document) = "HTMLDocument" Then
            'check the URL
            If InStr(GetOpenIEByURL.Document.URL, i_URL) > 0 Then
              'leave, we found the right window
                Exit Function
            End If
        End If
    Next
End Function

The known problem (would love an answer!)
* With IE 7 and beyond, there might be tabs within a window ... brief experiment shows that if you open google then activate another site on another tab ... this code will activate the IE WINDOW - but not the correct tab.

Notes:
1. The FullScreen on then off is an attempt to resolve this. On my machine, this hides the tabs ... so I'm hoping my user will open the site with my code then go back to it repeatedly and never be able to open another tab.

2. I prefer "early binding" because you know at compile if you have problems. However, experience says that some percentage of users won't touch this feature (I'm doing a right-click on an element of a list to launch a website related... not primary feature of my application). And of the people who use my tool, there is definitely SOMEONE who won't have the right reference. So - this code is half done ... I use early binding (set the reference and DIM the object the RIGHT way) so that I can see all the properties and methods as I type the code. But then I'll convert to late binding (have no reference and DIM as a generic Object ... as the "NewSite" is done). My plan is to make it all late binding and put it in my application.

3. SetForeGroundWindow works great. The ShowWindow is just there in case the window is minimized. The two together work fantastic.

4. the function was copied from: http://vba-corner.livejournal.com/4623.html and I just edited the search to be Instr instead of = because my webapp uses sub-pages. your mileage may vary.

-Jon B
 
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,754
Members
452,940
Latest member
rootytrip

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top