VBAでgetElementsByClassNameが使えないときの対処方法

ターゲットとなる「URL」のページはIEのドキュメントモードがIE8以下だとgetElementsByClassNameは未対応とのこと。

getAttribute("className")でクラス名をしらべながら処理するしかない

....

    Dim httpReq As XMLHTTP60
    Set httpReq = New XMLHTTP60
    
    httpReq.Open " GET", aUrl
    httpReq.send 'HTTPリクエスト送信
    
    Do While httpReq.readyState < 4 '処理待ち
        DoEvents
    Loop

    Dim htmlDoc As Object
    Set htmlDoc = New HTMLDocument
    htmlDoc.Write httpReq.responseText

    Dim divs As IHTMLElementCollection
    Set divs = htmlDoc.getElementsByTagName("div")
    
    Dim item As IHTMLElement
    For Each item In divs
        
        If item.getAttribute("className") = "hoge" Then
.....

ネタ元

-
www.atmarkit.co.jp