PDA

View Full Version : VBA pulling data from a table



SBrooky
05-18-2012, 03:38 AM
Hope somebody can help with this. Ive spent a few hours googling without any help.

I have a form which goes to a website (mycarcheck). Enters the registration in the textbox (MCCR) and presses submit then it goes to the next page which has a table with the result i want.

Typically it says "We have important information on our database regarding REGHERE, a Mg Zr+ 105 (5 Door Hatchback). Choose a check to proceed."

Id like to be able to get everything between the "REGHERE," and the fullstop. I know this is pretty difficult so id be happy just returning the entire thing into a different textbox (MCCMessage) and into A2 on sheet MyCarCheck.

Here is the code i have at the moment. As you can see its a mix of a few different methods ive tried from google searches.

Private Sub CommandButton1_Click()
Dim ie As Object
Dim elTableCells
Dim result As Variant

Set ie = CreateObject("internetexplorer.application")
ie.Visible = True
ie.navigate URLHERE

While ie.busy
DoEvents
Wend

ie.Document.getElementById("reg_no").Value = MCCR.Value
ie.Document.all("submit_button").Click

While ie.busy
DoEvents
Wend
elTableCells = ie.Document.getElementsByTagName("car_info")
Set result = ie.Document.getElementsByTagName("car_info")
Sheets("VehicleCheck").Range("A2").Value = result.Text
ie.Quit
Set ie = Nothing
End Sub
Here is the code for the table from the website:

<div id="option_choice"> <div id="choice_header_container"> <h1 class="block"> Vehicle Check for MYREG </h1> <div class="car_info"> <div id="notrightlink"><a href="#another_vrm_form" id="wrong_vehicle">Not the vehicle<br> you expected?</a></div> <p><strong style="color: red;">We have important information on our database regarding MYREG, a Mg Zr+ 105 (5 Door Hatchback). Choose a check to proceed.</strong></p> <div id="another_vrm_container" style="display: none;"> <div id="another_vrm"> <form id="another_vrm_form" action="htt ps://ww w.mycarcheck.co m/check/" name="checkform" method="get"> <h2>Not the vehicle you expected?</h2> <div class="box" style="margin-right: 15px; text-align: center;"> <strong>Try another registration number</strong> <input id="reg_no" name="reg_no" value="" class="vrm" size="15" type="text"> <input value="Check!" type="submit"> </div> <br> <div class="box"> <h3>Contact us</h3> <p>If you are sure this is the correct registration number <a href="ht tps://ww w.mycarcheck.c om/about/contact/">contact us</a> and we'll investigate further.</p> </div> <div class="spacer">&nbsp;</div> </form> </div> </div> </div> </div>
Any help would be great, I feel like the more things i try the further back i go.

To see the result page easier it might be worth just going to mycarcheck .co . uk and entering a registration to see.