Internet Explorer Automation Object Library - Update for Excel 2007


April 29, 2008 – 1:30 am by JP

One of the most popular pages on this site shows code for automating Internet Explorer. However I have only tested the code in Excel XP/2003. The purpose of this post is to credit a gentleman named Durand Sinclair who, using Excel 2007, pointed out to me that the name of the IE object library in Excel 2007 is actually called “Microsoft Browser Helper” (click Tools>References in the VBE). Once you select the checkbox, exit the dialog box and re-enter it, the name changes to “Microsoft Internet Controls”.

If anyone else would like to verify this behavior in Excel 2007 and let me know, I would be grateful to hear it.

Thanks Durand!

–JP


If you enjoyed this page:
  • StumbleUpon
  • Technorati
  • Digg
  • Google
  • del.icio.us
  • MisterWong

Print This Post Print This Post  |  Email This Post Email This Post  |  Permalink  |  Subscribe to this feed Subscribe now!

Filed Under: Excel, Internet Explorer, VBA, automation
Tags: , ,

This post has 999 views since April 29, 2008 – 1:30 am.
  1. 22 Responses to “Internet Explorer Automation Object Library - Update for Excel 2007”

  2. These references are not part of any Office library, but show all possible libraries installed on a computer. These may or may not be appropriate for a version of Office.

    Microsoft Internet Controls (C:\Windows\system32\shdocvw.dll) is different from Microsoft browser Helpers (C:\Windows\system32\browseui.dll). The former contains the Internet Explorer interface, the latter seems more related to handling of multimedia content.

    By Jon Peltier on Apr 29, 2008

  3. I’m getting the impression that not much has changed in Excel 2007 (programmatically), other than the drastic user interface changes. Since I don’t have a copy I’m not able to verify. Thanks Jon.

    By JP on May 1, 2008

  4. I have excel 2003 at work, and 2007 at home. I found that Microsoft Internet Controls wasn’t automatically in my reference library in 2007, so I had to browse to C:\Windows\system32\shdocvw.dll and add it. After that, everything worked perfectly. :)

    By Disco Lemonade on Sep 29, 2008

  5. there is one Additional Details button, please tell me the object name to access the additional details button from vba.

    By prem on Oct 22, 2008

  6. how to access an image control (click event) of a website from vba. can anyone find that for me. vba code like

    IeApp.Document.all.track.Click

    worked for me but not the image control. can anyone please find for me?

    By prem on Oct 22, 2008

  7. Prem,

    If you are trying to programmatically click a button on a web page, you’d need to view the source of the page to find out the name of the control, then set an object reference to that control and use the Click Method to programmatically “press” the button.

    There is some sample code here you might adapt for your purposes:

    http://www.codeforexcelandoutlook.com/AutomateInetExplorer.html

    Thx,
    JP

    By JP on Oct 22, 2008

  8. Hi JP, thanks for your prompt reply. I could find only the image control from the source code of that page. i need to have the click event for the button_addl_details which is an image control.

    please find me a solution in having the click event on the button_addl_details.gif.

    By prem on Oct 23, 2008

  9. hi JP, my previous post deletes the html code which i wanted to get to you.

    this is the portion of the code
    input type=”image” src=”images/button_addl_details.gif”

    how to have a click event on this image control? please help me.

    By prem on Oct 23, 2008

  10. Using the link I provided above, the code you need is something like:

    VBA:
    1. Set ElementCol = appIE.Document.getElementsByTagName("INPUT") 
    2.    
    3. For Each btnInput In ElementCol 
    4.     If btnInput.src = "images/button_addl_details.gif" Then 
    5.         btnInput.Click 
    6.         Exit For 
    7.     End If 
    8. Next btnInput

    Basically you are looking at all of the page elements called "input" (of which that button is one) and looking at the "src" tag. If it matches, click it.

    HTH,
    JP

    By JP on Oct 23, 2008

  11. Hi JP, thanks again for giving me something useful. However, the btnInput.src is not satisfying with any, resulting into not executing btnInput.Click. I will give you specifically what i am looking for. That is;

    Please open http://www.usps.com and you fill find the Track & Confirm text box on the right side.

    type this 16 digit tracing # 03062400000276026378 and then press Go

    you will get Track & Confirm sheet where you will find "Additional
    Details>" image control in red.

    I need the click event for that image control which i need to access from vba.

    Hope you understood what i am looking for.

    By prem on Oct 23, 2008

  12. What code have you got so far?

    By JP on Oct 23, 2008

  13. Sub ListLinks()

    Dim IeApp As InternetExplorer
    Dim IeDoc As Object
    Dim i As Long
    Dim MyScreen As Object
    Dim ImageCon As Variant
    Dim Name As String

    Set IeApp = New InternetExplorer
    IeApp.Visible = True
    IeApp.Navigate "http://www.usps.com"
    Do
    Loop Until IeApp.ReadyState = READYSTATE_COMPLETE
    Set IeDoc = IeApp.Document
    IeApp.Document.all.trackField.Value = "03062400000276026378"
    IeApp.Document.all.trackGo.Click
    Do
    Loop Until IeApp.ReadyState = READYSTATE_COMPLETE
    IeApp.Visible = True
    AppActivate IeApp

    Set ElementCol = IeApp.Document.getElementsByTagName("INPUT")

    For Each btnInput In ElementCol
    If btnInput.src = "images/button_addl_details.gif" Then
    btnInput.Click
    Exit For
    End If
    Next btnInput

    Set IeApp = Nothing

    End Sub

    By Prem on Oct 24, 2008

  14. Try this:

    VBA:
    1. Sub ListLinks()
    2.     Dim IeApp As InternetExplorer
    3.     Dim IeDoc As Object
    4.     Dim i As Long
    5.     Dim MyScreen As Object
    6.     Dim ImageCon As Variant
    7.     Dim Name As String
    8.     Dim imgbtn As MSHTML.HTMLButtonElement
    9.     Dim ElementCol As MSHTML.IHTMLElementCollection
    10.     Set IeApp = New InternetExplorer
    11.     IeApp.Navigate "http://www.usps.com"
    12.     Do
    13.     Loop Until IeApp.ReadyState = READYSTATE_COMPLETE
    14.     Set IeDoc = IeApp.Document
    15.     IeApp.Document.all.trackField.Value = "03062400000276026378"
    16.     IeApp.Document.all.trackGo.Click
    17.     Do
    18.     Loop Until IeApp.ReadyState = READYSTATE_COMPLETE
    19.     Set ElementCol = IeApp.Document.getElementsByTagName("INPUT")
    20.     For Each imgbtn In ElementCol
    21.       If imgbtn.Name = "Additional Details" Then
    22.         imgbtn.Click
    23.         Exit For
    24.       End If
    25.     Next imgbtn
    26.     IeApp.Visible = True
    27.     Set IeApp = Nothing
    28. End Sub

    By JP on Oct 24, 2008

  15. Hi JP,

    Its working, with putting the system into the wait mode for atleast 5 seconds before reading the input for imgbtn, otherwise it never reads it.

    Say, i have around thousand track numbers for usps.com which i need to get the status of each and everyone. suppose, if the internet gets bit down for a moment when the macro runs, resulting into not reading some from the source code, how will i temporarily stop executing the macro till the internet gets up.

    will this IeApp.ReadyState = READYSTATE_COMPLETE sorts this problem?

    please explain.

    By Prem on Oct 24, 2008

  16. You could add a timer inside the Do Loop that breaks out (and displays error message) if there is a long delay. For example

    VBA:
    1. Dim startTime as Timer
    2. Dim bBadExit As Boolean
    3. startTime = Timer
    4. Do
    5. If Timer - startTime = 10000 Then
    6.   bBadExit = True
    7.   Exit Do
    8. End If
    9. Loop Until IeApp.ReadyState = READYSTATE_COMPLETE
    10. If bBadExit Then
    11.   MsgBox "Took too long!"
    12.   Exit Sub
    13. End If

    This is just air code so you'll need to test it out to see how long the code should wait (the "If Timer - startTime = 10000" statement)

    Enjoy,
    JP

    By JP on Oct 24, 2008

  17. Hi JP,

    Its great to have your code working, thanks a lot. Now how to fix "Page Cannot be displayed" while running the macro, some sort of trap is required to read page cannot be displayed. Is there any way to read page cannot be displayed? Please help.

    By Prem on Oct 24, 2008

  18. Prem,

    "Page cannot be displayed" is text on the screen. The link I gave you has sample code for assigning the text of a webpage to a string variable. After loading each page, you would need to check for that string inside the webpage body. What function would you use to search for one text string inside another?

    --JP

    By JP on Oct 25, 2008

  19. No JP,

    I don't have any code for finding the Page Cannot be displayed.

    By Prem on Oct 28, 2008

  20. It's on the page I provided in my first reply.

    Declare a string variable and, after each page loads, assign "IeApp.Document.body.innerText" to it.

    To check for "Page cannot be displayed", use the Instr Function as follows:

    VBA:
    1. If InStr(<your string variable>, "Page cannot be displayed")> 0 Then
    2. Msgbox "Page cannot be displayed. Exiting now"
    3. Exit sub
    4. End If

    By JP on Oct 28, 2008

  21. Hi JP, great, everything is working fine, thanks a lot and please let me know how to print the web page that i had opened from vba.

    i want to print the web page to the pdf writer which converts the web page to a pdf format file. also, i want to save that file with a name from my excel file.

    please help me in this.

    By Prem on Oct 29, 2008

  22. I am trying to run the code but it is opening a new window instead of the main appIE object window when I use the Navigate method. I am using IE7. I appreciate any help.

    AD

    By AD1 on Nov 29, 2008

  23. The code will always create a new window. You won't be able to use the existing window.

    By JP on Dec 1, 2008

Post a Comment

To post VBA code in your comment, use [VBA] tags, like this: [VBA]Code goes here[/VBA].





Subscribe without commenting

Keep Reading:

Browse Posts:


« Contribute to this site! || Excel training class and Outlook file request system updates »