+ Reply to Thread
Results 1 to 8 of 8

Using VBA to input data into a web page

  1. #1
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,595

    Using VBA to input data into a web page

    Good evening all.

    I found this (example) code which should access Wikipedia in Internet Explorer), put some data in a box and press the search button. All works well until it tries to press the "Go" button. I suspect this may be old code and the button is no longer called "Go" but "searchButton".

    Anyway, two problems; if I leave it at "Go", I get an error: Run-time error '424', Object required. I thought, ah, I can cope with this, and edited it to "searchButton". This stops the error message but doesn't input the search term, it goes to the Search page as if I have cleared the search term (Document Object Model) ... so that's the second problem.

    Note: it requires references to Microsoft HTML Object Library and Microsoft Internet Controls.


    I would be grateful if someone could help me make this example work so that I can then adapt it to do other things. Alternatively, if you can provide code that does the same thing but in a different way, that would make me very happy too. Or, even better, a solution that isn't dependent on IE at all, but can use the default browser ... but I guess that could be asking a lot.

    Thanks in advance, TMS

    Please Login or Register  to view this content.

    There are several functions to support this worked example:

    Please Login or Register  to view this content.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  2. #2
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,551

    Re: Using VBA to input data into a web page

    Trevor,

    Im by no means a IE expert but just fooling around a little bit the the code I had the Idea of entering the search term then click the button then enter the search term again then click the button again. Well it worked go figure. Guess more of a work around then a solution. I used the searchButton intead of GO

    Please Login or Register  to view this content.
    Or even this works

    Please Login or Register  to view this content.
    Last edited by mike7952; 10-18-2012 at 07:15 PM.
    Thanks,
    Mike

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved.

  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,595

    Re: Using VBA to input data into a web page

    Mmmm, thanks Mike. That must be opening up the search page, entering the search item and then clicking search. Not ideal but I guess it must be something to do with that page.

    I'll have to try and find other examples

    Cheers

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,646

    Re: Using VBA to input data into a web page

    You have the name of the button wrong, it should be "searchButton" not "Go".

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,595

    Re: Using VBA to input data into a web page

    @Norie: I explained that at the start of my explanation ...

    I found this (example) code which should access Wikipedia in Internet Explorer), put some data in a box and press the search button. All works well until it tries to press the "Go" button. I suspect this may be old code and the button is no longer called "Go" but "searchButton".

    Anyway, two problems; if I leave it at "Go", I get an error: Run-time error '424', Object required. I thought, ah, I can cope with this, and edited it to "searchButton". This stops the error message but doesn't input the search term, it goes to the Search page as if I have cleared the search term (Document Object Model) ... so that's the second problem.

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,646

    Re: Using VBA to input data into a web page

    Sorry, I didn't see that part of the post.

    So even though you changed it in the code you ran it gave you the error?

    This is the quick and dirty way I would have done it.
    Please Login or Register  to view this content.

  7. #7
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: Using VBA to input data into a web page

    As an alternative for wikipedia using the default browser:
    Please Login or Register  to view this content.
    Automating Internet Explorer is usually not necessary, you can send the same request that a browser sends in Excel and return the result to Excel, it gets a little complex when dealing with sites that require you to log in, but they can usually still be automated. For an example, have a look at my attachment here:
    http://www.excelforum.com/excel-prog...cel-macro.html

  8. #8
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,595

    Re: Using VBA to input data into a web page

    Thanks guys, sorry it's taken me a little while to get back to you ... just started researching my family tree and got a little involved.

    @Norie: thanks. Your solution seems to be quite effective. I'm just trying to work out why ... the end stage seems to be the same but clearly something is different.

    @Kyle. thanks also. I probably need to spend some time dwelling on your solution (based on Leith Ross's sample workbook) as I suspect that is exactly the type of thing that I am going to want to do.

    Cheers, TMS

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1