We help IT Professionals succeed at work.

Using OIE To Open IE From VB6 App

983 Views
Last Modified: 2013-11-26
Using the code below, is there a way to force the opened IE window to have focus? There are multiple menu choices,  so the user may open 2 or more IE windows. The first window opens on top, but, if the first window is left open, the subsequent windows open behind the app. Thank you.



Dim strLink As String
Dim strFullLink As String


strLink = "http://intranet/default.aspx"

    Dim oIE As New InternetExplorer
   
    With oIE
        .Toolbar = False
        .MenuBar = False
        .Visible = True
        .FullScreen = False
        .AddressBar = False
                     
       
    End With

Select Case strReport
   
        Case "Misc Report"
            oIE.Navigate "http://intranet/default.aspx?Report=MiscReport&Year=2007&Dept=123&Class=XYZ"
           
        Case "Test Report"
            strFullLink = strLink & "?Report=" & strReport
            strFullLink = strFullLink & "&Year=" & strYear
            If strDept <> "" Then
                strFullLink = strFullLink & "&Dept=" & strDept
            End If


oIE.Navigate strFullLink
Comment
Watch Question

CERTIFIED EXPERT
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
I haven't had time to try your code, because unfortunately my computer needs to be rebuilt. Thank you for the suggestion.
CERTIFIED EXPERT

Commented:
>my computer needs to be rebuilt

So does mine, it works for a few hours then randomly just switches off.  

Bad luck, hope you get it sorted soon and it does not cost too much........

Author

Commented:
I've tested your code in my project, and it works well. Now the problem is that each IE window stays on top,  so to return to the application the user must drag the window out of the way. Is there a simple way to make the focus return to the application window while still keeping the IE windows open in the background? Thank you.

Author

Commented:
Just to clarify: I want the focus to return to the app when it is clicked, not automatically. As it exists, when a user clicks on the app window, the IE windows stay on top.
CERTIFIED EXPERT

Commented:
Ok so I think I understand how you need it to work, so just a few simple mods.....


Private Sub mnu_MyMenuOption_Click()

zOpenIE "http://MyServer/MyPage.htm"

End Sub

Private Sub  zOpenIE(psURL As String)

Dim oIE As New InternetExplorer
   
With oIE
    .ToolBar = False
    .MenuBar = False
    .Visible = True
    .FullScreen = False
    .AddressBar = False
End With

oIE.Navigate "http://www.bbc.co.uk"

' force to stay on top
SetWindowOnTop oIE.Hwnd, fsHWND_TOPMOST
DoEvents

' Now we may have to monitor page status but not sure right now.....
' But weshould now relegate the new IEWindow to a normal window
' It will stay on top but allow the app window to become top most

SetWindowOnTop oIE.Hwnd, fsHWND_NOTOPMOST

End Sub
CERTIFIED EXPERT

Commented:
Woops....

oIE.Navigate psURL

Author

Commented:
The program is now working as I intended. Thank you for all of your coding assistance.
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.