PDA

View Full Version : How to get the data from website (javascript) to excel by using vba



clif
08-09-2016, 12:46 AM
The Website:

<trclass="abc">
<td><inputname=" 01$ColumnAllSelector"type="checkbox" id=" 01_ColumnAllSelector"onclick="RowSelectorColumn_SelectAll( this );"/></td><td>StartDay</td><td>End Day</td><td>Numbers</td><td>Item</td>
<td>price</td><td>unit</td><td>qty</td><td> subtotal</td><td>remarks</td><td>Status</td><td>Name /td>

</tr><trclass="Row3">
<td><inputname="02$ColumnSelector"type="checkbox" id=" 02_ColumnSelector"onclick="RowSelectorColumn_CheckChildren( ' 01_ColumnAllSelector');" />
<script language='javascript'>
RowSelectorColumn_Register('01_ColumnAllSelector','02_ColumnSelector')
</script></td><td>01-01-2011</td><td>31-01-2011</td><td>0001</td><td>type1</td><td>$5,000.00</td><td>month</td><td>1</td><td>
$5,000</td><td>car rent</td><td>Finish</td><td>Chris Wong</td>

</tr><trclass="Row1">
<td><inputname=" 03$ColumnSelector"type="checkbox" id="03_ColumnSelector"onclick="RowSelectorColumn_CheckChildren( ' 01_ColumnAllSelector');" />
<script language='javascript'>
RowSelectorColumn_Register('01_ColumnAllSelector','03_ColumnSelector')
</script></td><td>01-02-2011</td><td>29-02-2011</td><td>0002</td><td> type2</td><td>$3,500.00</td><td>month</td><td>2</td><td>
$7,000</td><td>car rent</td><td>Finish</td><td>Amy Chan</td>

</tr><trclass="Row3">
<td><inputname=" 04$ColumnSelector"type="checkbox" id=" 04_ColumnSelector"onclick="RowSelectorColumn_CheckChildren( ' 01_ColumnAllSelector');" />
<script language='javascript'>
RowSelectorColumn_Register('01_ColumnAllSelector','04_ColumnSelector')
</script></td><td>01-02-2012</td><td>28-02-2012</td><td>0003</td><td> type1</td><td>$5,000.00</td><td>month</td><td>3</td><td>
$15,000</td><td>car rent</td><td>Not Yet Finish</td><td>Eric Chan</td>

</tr><trclass="Row1">
<td><inputname=" 05$ColumnSelector"type="checkbox" id="05_ColumnSelector"onclick="RowSelectorColumn_CheckChildren( ' 01_ColumnAllSelector');" />
<script language='javascript'>
RowSelectorColumn_Register('01_ColumnAllSelector','05_ColumnSelector')
</script></td><td>01-02-2011</td><td>29-02-2011</td><td>0002</td><td> type2</td><td>$3,500.00</td><td>month</td><td>2</td><td>
$7,000</td><td>car rent</td><td>Finish</td><td>Amy Chan</td>

[/HTML]




Sub Sample()
Dim objIe As Object, xobj As HTMLDivElement
Set objIe = CreateObject("InternetExplorer.Application")
objIe.Visible = True
objIe.navigate "http://www.abc.com"
While (objIe.Busy Or objIe.READYSTATE <> 4): DoEvents: Wend

Set xobj = objIe.Document.getElementById("")
Set xobj = xobj.getElementsByClassName("").Item(0)
Set xobj = xobj.getElementsByClassName("")(0)

Sheets("Sheet1").cell(1, 1) = xobj.innerText
Set xobj = Nothing
objIe.Quit
Set objIe = Nothing

End Sub

snb
08-09-2016, 02:28 AM
I couldn't find the website you are referring to.

clif
08-09-2016, 05:59 PM
Thanks!
This is only the structure of web. I just don't know how
to use these code to get data from this structure of web
to excel worksheet.

Set xobj = objIe.Document.getElementById("")
Set xobj = xobj.getElementsByClassName("").Item(0)
Set xobj = xobj.getElementsByClassName("")(0)