Question

Controlling Internet Explorer from VBA

In my VBA Excel application, I need to use Internet Explorer to obtain some required data. From my VBA program, I also need to be able to set values in the Internet Explorer within several textboxes, select a row in a listbox, and Click on a button all within Internet Explorer.

1. I activated the Internet Explorer using the following code:
      (Credit for this goes to leonstryker)

'=============================================================
Dim IE
Dim objShell

    Set IE = CreateObject("InternetExplorer.Application")
    Set objShell = CreateObject("WScript.Shell")
    With IE
        .Left = 20
        .Top = 20
        .Height = 540
        .Width = 950
        .MenuBar = 0
        .Toolbar = 1
        .StatusBar = 0
        .navigate "http://www.google.com"
        .Visible = True
    End With

    'wait until IE has finished loading itself.
    Do While IE.busy
        DoEvents
    Loop
   
    ' The Internet Explorer is now hopefully ready to accept commands/values or clicks.
    Stop
'==============================================================================

Since I do not know the names of All of the controls in all cases, I put together the following code to find all of the controls on a dummy form I created. It works fine on this dummy form, but what I really want is to be able to find all of the controls within the Internet Explorer. How do I make it look at the Internet Explorer Form rather than my dummy form?

'==============================================================================
Private Sub FindControls()
Dim Top As Integer
Dim Left As Integer
Dim Count As Integer
Dim Name As String
Dim Value As String
Dim temp As String
Dim Caption As String
Dim Enabled As Boolean
Dim Visible As Boolean
Dim FormControl As Control
   
    ' Find all of the controls on a VBA form. See VBA Help on "Controls Collection (Forms)"
    Count = Controls.Count            ' Total number of controls on Form
    For Each FormControl In Controls
        Name = FormControl.Name            ' get the name. ie. btn..., txt..., lst... etc.
        Top = FormControl.Top            ' Get its Top Location
        Left = FormControl.Left            ' get its Left location
        temp = Mid(Name, 1, 3)            ' Get first 3 characters of control name
      ' The 4 controls below don't have values.
        If temp = "frm" Or _
            temp = "lbl" Or _
            temp = "lst" Or _
            temp = "Img" Then
            Else
            Value = FormControl.Value      ' Get current value in the control
        End If
        Visible = FormControl.Visible      ' T/F is it visible
        Enabled = FormControl.Enabled      ' T/F is it enabled
    Next

End Sub
'====================================================================================

At this point I need to be able to place a text string in one or more textboxes, click on a row in a listbox and then programatically initiate an click_Event on a button.  This has to be done FROM within my VBA code TO the controls within the Internet Explorer.

Is anyone aware of any good books or articles that address how to manipulate Internet Explorer from witin a VBA program? So far I've had only marginal luck searching for information on this topic.

John

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2007-10-23 at 08:36:28ID22912137
Tags

vba

,

internet

,

explorer

Topics

VB Controls

,

Internet Explorer Web Browser

Participating Experts
1
Points
500
Comments
6

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. DoEvents Cmd for VBA for Access 97?
    Is there a similar "DoEvents" command in VBA for Access 97? Is it possible to port this or other commands over to VBA from VB?
  2. DoEvents
    Hi I have a procedure which creates a number of chartobjects resizes them and places them on a sheet. Another procedure called directly after picks up the chart objects and exports them to disk (gif). The Images are then opened in a userform. I am finding that the last ch...
  3. DoEvents
    Hi, I am decently fluent in VBA and VB5. I am now infrequently working in .NET. Does DoEvents work in .NET? Has it changed?
  4. what is DoEvents
    what is DoEvents and the purpose of it ?
  5. Disable a Word toolbar using VBA
    Using VBA, I need to disable the "Standard" toolbar for the currently active document, without affecting the normal.dot template
  6. Enable a toolbar with VBA
    Hi all, some questions I have a login page where i determine if the user if an admin or a normal user. I have disabled all the toolbars at startup. I would like to enable the toolbars if its an admin and disable otherwise. I've tried this, select case rights case "Adm...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: CbrinePosted on 2007-10-23 at 11:06:15ID: 20133014

John,
  I know you are not going down this path, but have you tried using the MS WebBrowser control?  It will allow you to create a control right inside of excel (like a button) that will allow you to open a web page.  Using this, you can make changes to the web page, and activate controls as well.  I just did some testing on this the other day.  I believe it will be much easier to work with, since it's a control embbed in excel vs trying to remote control and outside program.  You will need to do some research but once you figure it out, it works really well.

HTH
Cal

 

by: PropertyTaxAnalystsPosted on 2007-10-23 at 12:20:07ID: 20133679

Cbrine,

Do you have any simple sample code or examples that I might be able to look at or where should I go to find out more about MS WebBrowser controls.

You were right, this doesn't look like the path I had planned to follow, but I'm not sure that the path that I was on is the best or the worst. Once I find out more about MS WebBrowser controls they may be the best alternative.

Thanks for your quick response.

John

 

by: CbrinePosted on 2007-10-23 at 12:59:10ID: 20134058

Here's some code I used to login to a website and press a button using the webbrowser control.  You need to use the html name tags from the HTML Source in order to ID the correct control

WebBrowser1.Navigate "www.test.com"
WebBrowser1.document.all("username").setattribute "value", "Test"
WebBrowser1.document.all("password").setattribute "value", "test"
WebBrowser1.document.all("submit").Click

HTH
Cal

 

by: PropertyTaxAnalystsPosted on 2007-10-24 at 11:13:49ID: 20141465

Cal,
Thanks for your examples. I've done some testing based on your suggestions and had some luck. I am able to update the values in Internet Explorer from values from within my VBA program using the following (sample) code:

    IE.document.all("Address1").Value = "123 Michigan Ave"        ' Enter value for Street Address
    IE.document.all("City").Value = "Chicago"        ' Enter value for City
    IE.document.all("State").Value = "IL"                ' Enter value for State
    IE.document.all("Zip5").Value = ""                    ' Set ZIP code to null
    IE.document.all("Submit").Click                         ' Click on the "Submit" button to send request.

This is a HUGE step forward!!!

After my code performed the "Submit", I loop until IE is not busy.

However, I am having a problem trying read or obtain refreshed data from IE after I updated the  information above and my code clicked on the "Submit" button.  The browser screen has the correct values, but the way that I using to get the info from the browers to my program doesn't work. I've tried several deritivates such as:
       
    MyZIP = IE.Document.all("Zip5")

all with no success. Any suggestions?

Also, short of perusing the HTML file manually,  are there other ways to determine the "name" of a control or variable embedded in the HTML text. This area of expertise is not one of my strong points and if possible it really want to be able to find these names using code rather than a manual search. Is this wishful thinking?

Thanks very much,
John

 

by: CbrinePosted on 2007-10-26 at 06:27:33ID: 20155287

I'm new to it as well, so I've never tried extracting the data from the web site, just the sending, so I'm afraid you are on your own on that one.  I would have tried the same thing, expecting results as well.  As far as programmatically ID'ing the controls, I'm not sure.  I did see some code that allowed you to cycle through each of the tagts on the web page, but after testing, I was not able to see any real use for it.  It didn't ID the controls very well.  I will see if I can find it again and post it for you.

Cal

 

by: PropertyTaxAnalystsPosted on 2007-10-26 at 12:44:46ID: 20158479

Cal,
Thanks for your last comments. I was planning to journey down the path to look at each tag on a Web page but from your remarks you have saved me some time. If you can find it again I would like to see it just out of curiousity.
Thanks again for your help. It gets very frustrating sometimes when something appears to ve very simple but turns out to be complex. Unfortunately, the true downside of learning more is that it makes you realize how much you don't know.

John

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...