Sub tableToArray(document As MSXML2.DOMDocument, ary As Variant)
Dim wantedRows As Integer
Dim wantedColumns As Integer
wantedRows = UBound(ary, 1)
wantedColumns = UBound(ary, 2)
Dim tableRowCount As Integer
tableRowCount = document.selectNodes(").Length
Dim errorCondition As Boolean
Dim errorMessage As String
errorCondition = False
If (tableRowCount > wantedRows) Then
errorCondition = True
errorMessage = "Range too small: Need " & tableRowCount & " rows, have only " & wantedRows
End If
Dim row As Integer
For row = 0 To wantedRows
Dim tableColumnCount As Integer
Dim query As String
If (row > tableRowCount) Then
tableColumnCount = 0
Else
query = " & row & "]/td"
tableColumnCount = document.selectNodes(query).Length
End If
If (tableColumnCount > wantedColumns) Then
errorCondition = True
errorMessage = "Range too small at row " & row & " need " & tableColumnCount & " cols, have " & wantedColumns
End If
Dim col As Integer
For col = 0 To wantedColumns
If (row >= tableRowCount) Then
ary(row, col) = ""
ElseIf (col >= tableColumnCount) Then
ary(row, col) = ""
ElseIf (errorCondition) Then
ary(row, col) = errorMessage
Else
query = " & row & "]/td[" & col & "]"
ary(row, col) = convertToNiceType(document.selectSingleNode(query).text)
End If
Next col
Next row
End Sub
Function convertToNiceType(text As String) As Variant
On Error GoTo tryDate
convertToNiceType = CDbl(text)
Exit Function
tryDate:
If (IsDate(text)) Then
convertToNiceType = CDate(text)
Else
convertToNiceType = text
End If
End Function