[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Internet Explorer Always on top :  Vb6

Posted on 2004-09-25
7
Medium Priority
?
1,645 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

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!

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
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

656 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