Solved

Internet Explorer Always on top :  Vb6

Posted on 2004-09-25
7
1,606 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
  • 4
  • 2
7 Comments
 
LVL 85

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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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 85

Accepted Solution

by:
Mike Tomlinson earned 500 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

758 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now