Sub GetPricingFromWeb()
Dim IE As InternetExplorer
Dim HTMLDoc As IHTMLDocument
Dim Elements As IHTMLElementCollection
Dim Element As IHTMLElement, ElementList As IHTMLElement
Dim ElementTable As IHTMLTable
Dim incrRow As Long, incrCol As Long, LoopBReak As Long
Dim URL As String, strPN As String
strPN = "91731A049"
URL = "http://www.mcmaster.com/#" & strPN
Debug.Print "URL = " & URL
Set IE = New InternetExplorer
With IE
.navigate URL
.Visible = False
'Waiting till page loads
Do While .readyState <> READYSTATE_COMPLETE
DoEvents
Debug.Print "Waiting on IE" & Time
Loop
End With
Set HTMLDoc = IE.Document
'Wait till document load is complete
Do While HTMLDoc.readyState <> "complete"
DoEvents
Debug.Print "Waiting on document" & Time
Loop
Do While IsNull(HTMLDoc.getElementById("Prce")): DoEvents: Loop
If Not HTMLDoc Is Nothing Then
Set ElementList = HTMLDoc.getElementById("Prce") ' <-- error code 424, object required
Debug.Print "InnerHTML" & vbNewLine & ElementList.innerHTML
End If
If Not ElementList Is Nothing Then
Set Elements = ElementList.Children
Debug.Print "Number of elements " & Elements.Length
Else
GoTo SkipProcedure
End If
For Each Element In Elements
Debug.Print "Element Class name = " & Element.className
If Element.className = "PrceTierTbl" Then
Set ElementTable = Element
If Not ElementTable Is Nothing Then
Debug.Print "ElementTableRows"
For incrRow = 0 To ElementTable.Rows.Length - 1
For incrCol = 0 To ElementTable.Rows(incrRow).Cells.Length - 1
Debug.Print "InnerText @ (" & incrRow & "," & incrCol & ") = " & ElementTable.Rows(incrRow).Cells(incrCol).innerText
Next incrCol
Next incrRow
End If
End If
Next
IE.Quit
Exit Sub
SkipProcedure:
MsgBox "nothing happened"
IE.Quit
End Sub