PC Review


Reply
Thread Tools Rate Thread

Automanipulating IE drop-down list in VBA/Excel

 
 
Bob Bridges
Guest
Posts: n/a
 
      9th May 2008
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.
 
Reply With Quote
 
 
 
 
Tim Williams
Guest
Posts: n/a
 
      9th May 2008
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


"Bob Bridges" <(E-Mail Removed)> wrote in message
news:EDB62FC5-554C-45FC-BEB1-(E-Mail Removed)...
> 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.



 
Reply With Quote
 
Bob Bridges
Guest
Posts: n/a
 
      9th May 2008
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.

--- "Tim Williams" wrote:
> 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
>
> --- "Bob Bridges" <(E-Mail Removed)> wrote in message
> news:EDB62FC5-554C-45FC-BEB1-(E-Mail Removed)...
> > 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.

 
Reply With Quote
 
Tim Williams
Guest
Posts: n/a
 
      9th May 2008

Bob,

The code I posted worked for me as written.

Tim

On May 8, 11:21*pm, Bob Bridges <BobBrid...@discussions.microsoft.com>
wrote:
> 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.
>
>
>
> --- "Tim Williams" wrote:
> > 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

>
> > --- "Bob Bridges" <BobBrid...@discussions.microsoft.com> wrote in message
> >news:EDB62FC5-554C-45FC-BEB1-(E-Mail Removed)...
> > > 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.- Hide quoted text -

>
> - Show quoted text -


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to create drop down list from one excel file to another excel. Saravanan.G Microsoft Excel Misc 2 29th Nov 2008 05:57 PM
Excel Drop Down List Susan Microsoft Excel Misc 3 22nd Oct 2008 11:04 PM
How to Create a macro from drop down list (Validation List) in excel rajashekar14@yahoo.com Microsoft Excel Programming 0 31st Oct 2006 12:42 PM
My Excel drop-down list eliminates from list options chosen. Help =?Utf-8?B?U3liaWw=?= Microsoft Excel Programming 2 19th Jan 2006 09:19 PM
multiple select from the drop down list in excel. list in one sheet and drop down in sriramus Microsoft Excel Misc 5 27th Oct 2005 06:55 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:54 AM.