Home>

I want to operate IE11 from VBA in Excel (Office 365) and use getElementsByClassName to count how many elements have the same class name.

Error message

Run-time error '438':
The object does not support this property or method.

Applicable source code

Checked Microsoft Scripting Runtime, Microsoft Internet Controls, and Microsoft HTML Object Library in reference settings

Private Sub CountClass ()
    Dim IEobj As New Internet Explorer Medium
    IEobj.Navigate URL
    Call Util.WaitingForLoad (IEobj) 'Call a function that waits for IE loading and wait a little
    Dim myObj As Object
    Dim Counter As Integer
    For Each myObj In IEobj.Document.getElementsByClassName ("TestClass") '
        Counter = Counter + 1
    Next
End Sub

・ I have made similar tools using Excel (Office 365) and IE11 before, and they still work, so I set them to the same code and reference settings as the tools that are working except URLs. I tried it, but the same error doesn't happen
・ Confirm that there is definitely at least one "TestClass" class on the site
・ After searching, I found that "s" of getElements is missing or ClassName is HTML Collection, etc., but I think there is no problem
・ The same error will occur even if it is executed after taking a long time to load IE and displaying it securely
・ GetElementById and getElementsByTagName work for some reason.

I'm sorry, please help.

vba