-1

I'm trying to pull the "Available Balance" dollar amount from a web site and have the amount entered into my Excel sheet. Below is the code section from the web site and the page source is located here, http://pastebin.com/VsThEzEE. Thanks in advance for any suggestions.

<table class="bd-wizard-account-header">
    <tr>
        <td valign="bottom"><img src="/Content/images/tenants/visaUS/en-us/vgCard1.png" /></td>
        <td valign="bottom"><h6>Card Ending</h6><h5>0102</h5></td>
        <td valign="bottom"><h6>Available Balance</h6><h5>$0.00</h5></td>
        <td valign="bottom"><h6>Initial Balance</h6><h5>$300.00</h5></td>
    </tr>
</table>
Eric B
  • 11
  • 4
  • Where's your VBA code? What have you tried so far? Have you [searched for an answer](https://www.bing.com/search?q=automate+internet+explorer+with+vba) yet? – Tim Oct 12 '16 at 18:44
  • I really don't have any. I have searched and tried different things here and there hoping that I would find a sort of cookie cutter answer that would work for what I'm trying to do, but have not found anything that has worked so far. Also, my scripting skill are basically non-existing and whatever I have gotten working in the past regarding scripting is through hours of trial and error and googling. – Eric B Oct 12 '16 at 18:56
  • Possible duplicate of http://stackoverflow.com/questions/18709911/pull-data-from-website-using-vba-excel-multiple-classname. Move to close – nbayly Oct 12 '16 at 21:16
  • I don't believe that it is, I'm not trying to get image elements, at least I don't think so. I have tried different lines of code like ie.document.getelementsbyclassname but since I know next to nothing of the code syntax I'm basically guessing. I essentially have code that will pull the balance of gift cards for me, http://stackoverflow.com/questions/39883101/excel-vba-to-enter-data-online-with-ie-and-loop-through-rows, and wanted to go a step further and see if it was possible to grab the "Available Balance" from the web site as well. – Eric B Oct 12 '16 at 22:04

2 Answers2

1

After more searching, I was able to pull the info that I needed and enter it into my Excel sheet with the following.

  Dim dd As String
  dd = IE.Document.getElementsByTagName("h5")(1).innerText
  ActiveCell.Value = dd
Eric B
  • 11
  • 4
0

It is also the third td tag within the element with className "bd-wizard-account-header" with the tag table

Without knowing how many tables there are you could use the equivalent CSS selector, as described above, of:

table.bd-wizard-account-header td:nth-child(3)

or potentially just

.bd-wizard-account-header td:nth-child(3)

CSS selector query on HTML supplied:

CSS query


Reference material:

  1. CSS Class selector
  2. nth-Child

VBA:

You can apply the selector via the .querySelector method of the IE.Document. .querySelectorAll if table/class index is greater than 0 i.e. there are more than one the page and the one you require is not the first.

Example syntax:

IE.Document.querySelector("table.bd-wizard-account-header td:nth-child(3)").innerText
QHarr
  • 83,427
  • 12
  • 54
  • 101