+ Reply to Thread
Results 1 to 6 of 6

ERROR 438 - GetElementsByClassName on VBA

Hybrid View

jdlf ERROR 438 -... 12-12-2018, 02:46 PM
CK76 Re: ERROR 438 -... 12-12-2018, 03:22 PM
jdlf Re: ERROR 438 -... 12-17-2018, 07:38 AM
CK76 Re: ERROR 438 -... 12-17-2018, 09:40 AM
jdlf Re: ERROR 438 -... 12-19-2018, 08:21 AM
CK76 Re: ERROR 438 -... 12-19-2018, 11:22 AM
  1. #1
    Registered User
    Join Date
    12-12-2018
    Location
    Brazil
    MS-Off Ver
    2016
    Posts
    3

    ERROR 438 - GetElementsByClassName on VBA

    Hi guys
    this is my first question here, hope you see me often from now on.

    I was using a code today, and it was running perfectly this morning - And now, i get "RUN-TIME ERROR '438': Object doesn't support this property or method"
    the error occurs on this line of code:

    [CODE]For Each oElement In .document.getElementsByClassName("painelAprovacaoItem")[\CODE]

    Weird thing: If I change getElementsByClassName to getElementsByTagName it runs properly, but it doesn't works for what I need.

    does anyone knows what it could be?

    Follow the complete code:

    Sub Acoes()
    
        Sheets("Ações").Select
        Rows("2:2").Select
        Range(Selection, Selection.End(xlDown)).Select
        Selection.Delete
        
          
    
        Set ie = CreateObject("internetexplorer.application") 'Abrir IE
        
        iRow = 5
        iRowa = 2
        Sheets("PAs").Select
        
        While Range("B" & iRow).Value <> ""
            
            PA = Range("B" & iRow).Value
            
            With ie
            .Visible = True
            .navigate "url"
            
            Do While .busy Or _
                .readystate <> 4
                DoEvents
            Loop
            
            .document.getElementByID("txtCodigo").Value = PA
            .document.getElementByID("btnConsultar").Click
            
            Do While .busy Or _
                .readystate <> 4
                DoEvents
            Loop
            
            .document.getElementByID("dgResultado__ctl3_lblTituloValor").Click
            
            Do While .busy Or _
                .readystate <> 4
                DoEvents
            Loop
    
              
            For Each oElement In .document.getElementsByClassName("painelAprovacaoItem")
                MsgBox (oElement)
                Acao = oElement.Children(0).InnerText
                Descricao = oElement.Children(1).InnerText
                Responsavel = oElement.Children(2).InnerText
                Vencimento = oElement.Children(4).InnerText
                Status = oElement.Children(5).InnerText
                    
                If Status = "Cancelada " Or Status = "Concluída " Then
                Else
                    Workbooks("PA - RI.xlsm").Activate
                    Sheets("Ações").Select
                    Range("A" & iRowa).Value = PA
                    Range("B" & iRowa).Value = Acao
                    Range("C" & iRowa).Value = Descricao
                    Range("D" & iRowa).Value = Responsavel
                    Range("E" & iRowa).Value = Status
                    Range("F" & iRowa).Value = Vencimento
                    iRowa = iRowa + 1
                End If
                
            Next oElement
    
            Sheets("PAs").Select
            iRow = iRow + 1
    
            
            End With
        Wend
           
        ie.Quit
        
        MsgBox "Done"
    
    End Sub

    thanks a lot :D

  2. #2
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,973

    Re: ERROR 438 - GetElementsByClassName on VBA

    For ClassName you'd need reference to the external library.

    This is one of the quirk in HTML library. getElement(s)Byxxxx can misbehave except for TagName, ID.
    "Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something."
    ― Robert A. Heinlein

  3. #3
    Registered User
    Join Date
    12-12-2018
    Location
    Brazil
    MS-Off Ver
    2016
    Posts
    3

    Re: ERROR 438 - GetElementsByClassName on VBA

    Quote Originally Posted by CK76 View Post
    For ClassName you'd need reference to the external library.
    CK76, I didn't get it!
    can you give me an example, please? :D

  4. #4
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,973

    Re: ERROR 438 - GetElementsByClassName on VBA

    Here's sample code I posted in another forum.
    Sub torrent_info()
      Dim IE As New InternetExplorer, html As HTMLDocument, post As Object, n_url As String
    
      With IE
            .Visible = False
            .navigate "https://yts.am/browse-movies"
          Do Until .readyState = READYSTATE_COMPLETE: Loop
          Set html = .document
      End With
    
      ForEach post In html.getElementsByClassName("browse-movie-bottom")
          With post.getElementsByTagName("a")
              If .Length Then n_url = n_url & vbNewLine & .Item(0).href
          End With
      Next post
        MsgBox Replace(n_url, vbNewLine, "", 1, 1)
    
        IE.Quit
    EndSub
    In VBE, go to Tools->References. And add Microsoft HTML Object library and Microsoft Internet Controls library to your project.
    This will ensure that you can access all the available methods (though there are few minor quirks even when library is added, such as when writing to HTMLFile object).

    Note: Looks like some spaces got removed when I copied and pasted. I think I fixed it, but may have missed some.
    Last edited by CK76; 12-17-2018 at 09:57 AM.

  5. #5
    Registered User
    Join Date
    12-12-2018
    Location
    Brazil
    MS-Off Ver
    2016
    Posts
    3

    Re: ERROR 438 - GetElementsByClassName on VBA

    Thanks CK76, it worked for me!!! :D

  6. #6
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,973

    Re: ERROR 438 - GetElementsByClassName on VBA

    You are welcome

    If your issue is resolved. Please mark the thread as solved by using Thread tools found at top of your initial post.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] doc.GetElementsByClassname with weirdly formatted classnames
    By JasperD in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-23-2016, 12:58 PM
  2. [SOLVED] IE.Document.getElementsByClassName Object not supporting property or method
    By kamelkid2 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-04-2014, 08:17 AM
  3. [SOLVED] Run-tim error -2147467259(80004005): Automation error Unspecidied error
    By mattress58 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-25-2014, 12:12 PM
  4. [SOLVED] getElementsByClassName Wildcard Character?
    By killerkoz17 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-08-2013, 08:10 AM
  5. [SOLVED] getElementsByClassName from Yammer causing Run-time error 91
    By gerainta in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 06-20-2013, 05:49 AM
  6. Error "run-time Error '1004': General Odbc Error
    By D4WNO77 in forum Access Tables & Databases
    Replies: 2
    Last Post: 07-16-2012, 09:55 AM
  7. Error Handling - On Error GoTo doesn't trap error successfully
    By David in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-16-2006, 02:10 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1