?
Solved

Internet Explorer Always on top :  Vb6

Posted on 2004-09-25
7
Medium Priority
?
1,635 Views
Last Modified: 2011-10-03
Hello Expert ,

I am using  the code below to open a web page , but sometimes the web page does not
always come to the front

How can i make sure the web page will always be displayed on top.


Private Sub Command1_Click()

Dim abc
 
     
    abc = "http://www.google.co.uk"
   
     
    Dim IE As New InternetExplorer   '  also add Reference to Microsoft Internet Controls
    IE.Navigate abc    ' Goto Web Address in variable i here
    IE.Visible = True

End Sub

'-----------------------------------------------------------------------------------------------------
Also in seperate code

How can i use an existing instance of IE  to display my web page rather than open
a new instance every time.

thanks experts








0
Comment
Question by:Jimmyx1000
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 12153519
Here are both of the problems addressed:

Option Explicit

Private Declare Function BringWindowToTop Lib "user32" (ByVal hwnd As Long) As Long

Private IE As InternetExplorer   '  also add Reference to Microsoft Internet Controls

Private Sub Form_Load()
    Set IE = New InternetExplorer
End Sub

Private Sub Command1_Click()
    Dim url As String
    url = "http://www.google.co.uk"
    IE.Navigate url    ' Goto Web Address in variable i here
    IE.Visible = True
    BringWindowToTop IE.hwnd
End Sub

Private Sub Command2_Click()
    Dim url As String
    url = "http://www.google.com"
    IE.Navigate url
    IE.Visible = True
    BringWindowToTop IE.hwnd
End Sub
0
 

Author Comment

by:Jimmyx1000
ID: 12153627
Hello Expert

Your 1st Code is good thankyou ( Command1 )

In Command2

Command2  works fine first time but then if you close  this IE instance

it gives an error

Automation error
the object invoked has disconnected from its clients




0
 
LVL 14

Expert Comment

by:aelatik
ID: 12153631
This code will look for open IE sessions and use one if available, otherwise it will create a new instance :

Private Sub Form_Load()
        Dim DONE As Boolean
            DONE = False
        Dim IE As New InternetExplorer
        Dim WIN As New SHDocVw.ShellWindows
        ' Loop through all open Internet Explorer Sessions
        For Each IE In WIN
            If IE.LocationURL <> "" Then
                IE.Navigate "http://www.google.com"
                IE.Visible = True
                DONE = True
                Exit For
            End If
        Next
        ' If there is no instance, create a new one
        If DONE = False Then
            IE.Navigate "http://www.google.com"
            IE.Visible = True
        End If
End Sub
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 14

Expert Comment

by:aelatik
ID: 12153632
It also requires a reference to microsoft internet controls !
0
 
LVL 14

Expert Comment

by:aelatik
ID: 12153633
BTW, it will also bring the window to foreground with ( IE.visible=true )
0
 
LVL 14

Expert Comment

by:aelatik
ID: 12153636
Just put it in a command click event and try it out

Private Sub Command1_Click()
        Dim DONE As Boolean
            DONE = False
        Dim IE As New InternetExplorer
        Dim WIN As New SHDocVw.ShellWindows
        ' Loop through all open Internet Explorer Sessions
        For Each IE In WIN
            If IE.LocationURL <> "" Then
                IE.Navigate "http://www.google.com"
                IE.Visible = True
                DONE = True
                Exit For
            End If
        Next
        ' If there is no instance, create a new one
        If DONE = False Then
            IE.Navigate "http://www.google.com"
            IE.Visible = True
        End If
End Sub
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 total points
ID: 12153655
If you only want to reuse the IE window you created then declare it WithEvents and then you can trap the OnQuit() event:

Option Explicit

Private Declare Function BringWindowToTop Lib "user32" (ByVal hwnd As Long) As Long

Private WithEvents IE As InternetExplorer

Private Sub Command1_Click()
    openURL "http://www.google.co.uk"
End Sub

Private Sub Command2_Click()
    openURL "http://www.google.com"
End Sub

Private Sub openURL(ByVal url As String)
    If IE Is Nothing Then
        Set IE = New InternetExplorer
        While IE.Busy
            DoEvents
        Wend
    End If
    IE.Navigate url
    IE.Visible = True
    BringWindowToTop IE.hwnd
End Sub

Private Sub IE_OnQuit()
    Set IE = Nothing
End Sub
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question