VBA to grab 9 specific pieces of data from a website

  • Hello vba gurus, I have the VBA to launch IE, however am having an issue getting started on VBA for grabbing some specific data from a private website. I've searched a bunch of sites, and found some codes that are sort of remotely close, but usually looping through a table of same data, or it's just different enough to short circuit attempts. I have looked into definitions and am gaining some rudiment understanding, but you can probably smell the smoke from my brain after this week.


    Anyhow I would appreciate any help with this. The html code for each item is listed below, if it was in a named item/class I included that. There's no bigger container item for the TD items (like a Div).


    Here's the data that I need to pull in and put on a spreadsheet starting in A1. The items listed are in the order that they appear on the site with the text area box being at the bottom since it's big. There are page text items and there are field values needed.



    Thanks for any assistance.

  • Forgot to mention that this is a .asp site but it does show the page you are on as an id (domain.com/la/dir/page.asp?id=123456)


    The part of the code that is failing is on the "Document" object?


    sURL is the site, for testing though this will be changed to grab the url from a Cell on another page.


    The "If" statement is the only way to get a wait working. The usual "While" method fails and gives error that clients have disconnected.



    Every time I reference the word Document or HTMLDocument or IHTMLDocument in that spot it fails.


    I've tried with early binding on the internet explorer - as object as well without luck.


    Thanks for any assistance!

  • The trouble with referencing multiple elements in one line, as your For Each line does, is that you can't tell which part is failing. (The error is probably caused by getElementbyClassName - it should be getElementsByClassName.)


    Try this for the first four items - the others should be similar. Add a reference to MS HTML Object Library.


  • omg ima no0b, hopefully it's that simple, this is what happens when you stop coding for a few years and try to jump back in....will let you know tomorrow, thanks John!!!

  • A few errors, First tried just adding the s i missed, but that gave a generic error. so next substituted the code below- made notes on the errors right below the lines. Thanks for your help John, this is a challenging task.




    If this is impossible like this, i may have to try to open ie and save the page so i can get it into excel.

  • Seems this runtime error 462 <the remote server machine does not exsist or is unavailable> is the underlying issue with all code trying to grab my site. The code works for other sites.


    The site itself is using Javascript to pull in form data into its text boxes.


    Even these below are giving the error, so solve the error, and all different types should work. Ug....watch it be something simple...please post any ideas, thanks!!!

    Code
    IE.ExecWB 17, 0 IE.ExecWB 12, 2  
     &     
     IE.ExecWB OLECMDID_SELECTALL, OLECMDEXECOPT_DODEFAULT  IE.ExecWB OLECMDID_COPY, OLECMDEXECOPT_DODEFAULT
  • I had to resort to send keys to just copy the entire page. The site really is a userform where most of the data I wanted was in textboxes. Seems it is un-get-able any other way. Once it was in the spreadsheet, I just looped through the textboxes and copied the values to another sheet. From that point it was all formatting. Thanks for trying folks.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!