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
Print This Post
|
Email This Post
|
Permalink
|
Filed Under: Excel, Internet Explorer, VBA, automation
Tags: automation, Internet Explorer, object library
This post has 999 views since April 29, 2008 – 1:30 am.







22 Responses to “Internet Explorer Automation Object Library - Update for Excel 2007”
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
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
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
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
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
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
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
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
Using the link I provided above, the code you need is something like:
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
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
What code have you got so far?
By JP on Oct 23, 2008
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
Try this:
By JP on Oct 24, 2008
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
You could add a timer inside the Do Loop that breaks out (and displays error message) if there is a long delay. For example
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
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
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
No JP,
I don't have any code for finding the Page Cannot be displayed.
By Prem on Oct 28, 2008
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:
By JP on Oct 28, 2008
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
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
The code will always create a new window. You won't be able to use the existing window.
By JP on Dec 1, 2008