• Examples Of Using Late Binding To Connect To Internet Explorer

    Introduction:
    This article contains an example of using late binding to create a new instance of Internet Explorer.

    Please note that you can copy these code examples into any application that supports VBA, but the called application must be installed on your system for it to work. Just copy them into a standard module and run them. (No references need to be set in the Visual Basic Editor in order to make this code work.)

    Create a New instance of Internet Explorer:
    This code will create a new instance of Internet Explorer and bind to it. It will then navigate to the ExcelGuru home page.
    Code:
    Public Sub CreateInternetExplorer()
        'Author       : Ken Puls (www.excelguru.ca)
    
    
        'Create an instance of Microsoft Internet Explorer
        Dim objApp As Object
    
    
        'Create instance and set to visible
        On Error GoTo ErrHandler
        Set objApp = CreateObject("InternetExplorer.Application")
        With objApp
            .Visible = True
        End With
    
    
        'Add some text to the document
        With objApp
            .Navigate Url:="http://www.excelguru.ca/"
        End With
    
    
    ErrHandler:
        'Release the object and resume normal error handling
        Set objApp = Nothing
        On Error GoTo 0
    End Sub
    Bind to an existing instance of Internet Explorer:
    You cannot use the GetObject method used for the rest of the applications to bind to an existing Internet Explorer instance. In order to do this, we need to reach to a different method using Microsoft Internet Controls:
    Code:
    Public Sub GetInternetExplorer()
        'Edited/Annotated by: Ken Puls (www.excelguru.ca)
        'IMPORTANT:  Requires reference to Microsoft Internet Controls!
        'Go to Tools --> References --> Microsoft Internet Controls
    
    
        Dim shellWins As SHDocVw.ShellWindows
        Dim explorer As SHDocVw.InternetExplorer
        
        Set shellWins = New SHDocVw.ShellWindows
        
        For Each explorer In shellWins
            If explorer.Name = "Internet Explorer" Then
                Debug.Print explorer.LocationURL
                Debug.Print explorer.LocationName
            End If
        Next
        
        Set shellWins = Nothing
        Set explorer = Nothing
    
    
    End Sub

     

    I'm afraid that you must be logged in to comment or leave a testimonial. I wish it could be otherwise, but I'm trying to keep my site spam free for everyone's benefit. If you don't yet have an account it's completely free to sign up, and a very quick process. Simply click here to Register. Not only can you post a comment here, but it gives you full access to posts questions in our forum as well!

     

    If you already have an account, and just haven't logged in yet, what are you waiting for? Login Now!

  • MVP Logo
  • Recent Forum Posts

    alansidman

    Best method to create training log?

    Follow up to Ali's suggestion. Here is a link that I often refer Access Template Lookers to examine. While it does not give you an actual DB, it does...

    alansidman Today, 05:54 AM Go to last post
    p45cal

    Need help with total monthly hours

    Enter times as follows: If it's 2:05 in the afternoon enter as 2:05 PM or 14:05.
    The attached should handle times across midnight, but check....

    p45cal Yesterday, 11:22 PM Go to last post
    dcope7

    Need help with total monthly hours

    I took the 12 out and if you key in 0:30 it row 12 it still subtracts from row 16 which is what it is supposed to do. I've tried every format I could...

    dcope7 Yesterday, 07:05 PM Go to last post
    p45cal

    Need help with total monthly hours

    It does not! it adds the value 12 and doesn't even look at row 12! In this context it adds 12 days (=288 hours). Barmy.
    Until you get formulae right...

    p45cal Yesterday, 06:02 PM Go to last post
    dcope7

    Need help with total monthly hours

    Ok row 16 calculates rows 11 and 15, plus it subtracts row 12 and yes I know I have it adding but if you actually add 0:30 in row 12 it will subtract...

    dcope7 Yesterday, 05:23 PM Go to last post