I am new to macros and VBA, so may ask some stupid question. I want to create a macro that will automatically enter data to a webpage and copy the result and paste to anther web. Now, I am able to let macro to loop through the result which is a table, but can't locate to the data I want.
The result table It's like below:
'<table class="contentContainer">
' <tr class="heading">…</tr>
' <tr class="odd">
'<td class="value">xxx-xxx-xxx-xx</td>
'<td class="value"></td>
'<td class="money">$999.00</td>
….
How ever my code only can locate the whole table, not the 11 digits number(xxx-xxx-xxx-xx) I need.
Function BillingSearch(ByRef IE As Object) As String
'Get policies in the user's queue
Dim TableNum, NextRow, CellIncre, blnFlag As Boolean, blnStartTable As Boolean
Dim intRemove As Integer, strPolicy As String
Dim doc As Object, intFlag As Integer
On Error GoTo Err
TableNum = 0
NextRow = 0
CellIncre = 1
Set doc = IE.Document
'Loop through each table
For Each Table In doc.getElementsByTagName("TABLE")
TableNum = TableNum + 1
'Loop through each table row
For Each TableRow In Table.Rows
NextRow = NextRow + 1
'Loop through each cell
For Each TableCell In TableRow.Cells
CellIncre = CellIncre + 1
Debug.Print TableCell.innerText
'Flag on Past Due
If Trim(TableCell.innerText) = "PastDue" Then
blnFlag = True
MsgBox "stop"
End If
If blnFlag = True Then 'And CellIncre = 10
MsgBox "stop"
BillingSearch = TableCell.innerText
Exit Function
End If
Next TableCell
CellIncre = 0
Next TableRow
NextRow = 0
Next Table
'Show all the policies to allow for user selection
BillingSearch = ""
Exit Function
Thanks in advance for your help!
The result table It's like below:
'<table class="contentContainer">
' <tr class="heading">…</tr>
' <tr class="odd">
'<td class="value">xxx-xxx-xxx-xx</td>
'<td class="value"></td>
'<td class="money">$999.00</td>
….
How ever my code only can locate the whole table, not the 11 digits number(xxx-xxx-xxx-xx) I need.
Function BillingSearch(ByRef IE As Object) As String
'Get policies in the user's queue
Dim TableNum, NextRow, CellIncre, blnFlag As Boolean, blnStartTable As Boolean
Dim intRemove As Integer, strPolicy As String
Dim doc As Object, intFlag As Integer
On Error GoTo Err
TableNum = 0
NextRow = 0
CellIncre = 1
Set doc = IE.Document
'Loop through each table
For Each Table In doc.getElementsByTagName("TABLE")
TableNum = TableNum + 1
'Loop through each table row
For Each TableRow In Table.Rows
NextRow = NextRow + 1
'Loop through each cell
For Each TableCell In TableRow.Cells
CellIncre = CellIncre + 1
Debug.Print TableCell.innerText
'Flag on Past Due
If Trim(TableCell.innerText) = "PastDue" Then
blnFlag = True
MsgBox "stop"
End If
If blnFlag = True Then 'And CellIncre = 10
MsgBox "stop"
BillingSearch = TableCell.innerText
Exit Function
End If
Next TableCell
CellIncre = 0
Next TableRow
NextRow = 0
Next Table
'Show all the policies to allow for user selection
BillingSearch = ""
Exit Function
Thanks in advance for your help!