Automanipulating IE drop-down list in VBA/Excel

B

Bob Bridges

I'm strictly a newbie in VB; I've been programming on the mainframe for
decades but am only recently come to VBA, VBScript etc, so if you notice that
I'm going about this all wrong, be sure and point me in a better direction.
I have a spreadsheet that contains data from the web, and I'd like to make it
smart enough to update itself when I tell it to. I've learned a little about
the "Document" object model, and have gotten to the point where I can browse
down through all the .Document.All items and figure out which ones I want VBA
to manipulate. I can even fill in the values of web pages' text boxes and
simulate a .Click on its buttons.

But now I want to make a selection from a drop-down box. Let's say it has a
list of states on it: I want my VBA program to pick out the correct state
and convince the web page that I've chosen it. I've found the Option items
that define the possible selections, and I see that if I find the correct one
and change its Selected property to True, it shows up on the page correctly
as though I selected it myself.

But what the page doesn't do is proceed from that point as though I had
clicked on the item - that is, it shows up in the drop-down selection box,
but I can't get it to go forward from there. I've tried .Clicking on
everything I can think of (might have missed one, though), but nothing seems
to work. What am I supposed to do to get to the next step.

If there's a FAQ on this, or another forum I should post to, just point me
in the right direction. And if there's an easier way than using the Document
object model - which wouldn't surprise me - feel free to point that out to
me, too. Thanks.
 
T

Tim Williams

Is this a drop-down which when changed should trigger some kind of action ?

Try selecting the option and then calling the "onchange" event handler:

Set t = IE.document.getElementById("slctColor")
t.selectedIndex = 2
t.onchange


Tim
 
B

Bob Bridges

The object I'm working with appears to have the TypeName "HTMLSelectElement".
I don't see the OnChange method for the select object in the DOM
documentation.

But you got me started: There's something called fireEvent that I can use
to simulate the OnChange event by simply naming it:

t.fireEvent("OnChange")

I'll play with it after I've gotten some sleep. If I'm on the wrong track,
feel free to say so; I'm still discovering where all the documentation is
hiding. Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top