+ Reply to Thread
Results 1 to 9 of 9

Excel/VBA - Clicking checklist (HTML). Why not work?

Hybrid View

  1. #1
    Registered User
    Join Date
    08-28-2012
    Location
    Brazil
    MS-Off Ver
    Excel 2003
    Posts
    5

    Question Excel/VBA - Clicking checklist (HTML). Why not work?

    Good morning! I am developing a macro to click a few buttons on a page, but some are not working. Does anyone know why?
    CLICAR BOTOES PAGINA.zip

    Sub teste()
    Dim ie
    Dim obj
    Dim obj2
    Dim linkCollection2
    Dim elemCollection
    Dim t As Integer
    Dim r As Integer, c As Integer
        
    Set ie = CreateObject("internetexplorer.application")
    ie.Navigate2 "http://www.infomoney.com.br/mercados/agendas"
     ie.Visible = True
    
    Do While ie.Busy
    Loop
    Do Until ie.Document.ReadyState = "complete"
    Loop
    
    
    Dim LinkFound As Boolean
    Dim linkCollection
    
    
    Set linkCollection = ie.Document.getElementsByTagName("A")
    For Each link In linkCollection
    If link.InnerText = "Resultados" Then
    LinkFound = True
    link.Click
    Exit For
    End If
    
    Next
    
    
    If Not LinkFound Then
    MsgBox "Link Not Found!"
    Exit Sub
    End If
    
    Do While ie.Busy
    Loop
    Do Until ie.Document.ReadyState = "complete"
    Loop
    
    
        For Each obj In ie.Document.All.Item("ctl00$cphContent$ctl02$ddlReferencePage").Options
            If obj.InnerText = "3T12" Then
                obj.Selected = True
              '  ie.Document.forms(0).submit
                Exit For
            End If
        Next obj
        
        Set linkCollection2 = ie.Document.getElementsByTagName("A")
    For Each link In linkCollection2
    If link.InnerText = "Resultados" Then
    LinkFound = True
    link.Click
    Exit For
    End If
    
    Next
    
            Set elemCollection = ie.Document.getElementsByTagName("TABLE")
        
        For t = 0 To elemCollection.Length - 1
            For r = 0 To elemCollection(t).Rows.Length - 1
                For c = 0 To elemCollection(t).Rows(r).Cells.Length - 1
                    ThisWorkbook.Worksheets(1).Cells(r + 1, c + 1) = elemCollection(t).Rows(r).Cells(c).InnerText
                Next c
            Next r
        Next t
    
    ' TO FROM HERE DOES NOT WORK. WHY?
    
        For Each obj2 In ie.Document.All.Item("tblCInvestorData_length").Options
            If obj.InnerText = "100" Then
                obj2.Selected = True
              '  ie.Document.forms(0).submit
                Exit For
            End If
        Next obj2
    
    End Sub
    Thanks in advance for any help.

    Silmar

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Excel/VBA - Clicking checklist (HTML). Why not work?

    The code doesn't actually find the 'checklist' as the If isn't quite right.

    This is looking at the innertext of obj, not obj2.
    If obj.InnerText = "100" Then
    Also, it's looking for innerText to be the string '100'.

    This will find the 'checklist'.
      If obj2.InnerText Like "*100*" Then
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    08-28-2012
    Location
    Brazil
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Excel/VBA - Clicking checklist (HTML). Why not work?

    Norie, I'm sorry, but do not get it right. I have to change the code like this:

    For Each obj2 In ie.Document.All.Item("tblCInvestorData_length").Options
            If obj.InnerText = "*100*" Then
                obj2.Selected = True
              '  ie.Document.forms(0).submit
                Exit For
            End If
        Next obj2
    You know how to "click" the button that takes you to the page "2"?

    thank you very much

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Excel/VBA - Clicking checklist (HTML). Why not work?

    Why didn't you use the code I suggested?

    What is it you actually want to do anyway?

    The 'checklist' you seem to want to access is for setting the number of results that will appear on the page, not to move to the next page.

    To move to the next page you need to click a button with the id 'tblScheduleData_next'.
        Set obj2 = ie.document.getelementbyid("tblScheduleData_next")
        
        obj2.Click

  5. #5
    Registered User
    Join Date
    08-28-2012
    Location
    Brazil
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Excel/VBA - Clicking checklist (HTML). Why not work?

    Norie, forgive me, but I made the changes you suggested, but is giving error in execution. See what I did:

    For Each obj2 In ie.document.all.Item("tblCInvestorData_length").Options ' IS GIVING ERROR IN THIS LINE
            If obj2.innerText = "*100*" Then
                obj2.Selected = True
                          Exit For
            End If
        Next obj2
    The page has more than 200 lines, then even after clicking "100", I'll have to go to page "2" to download the remaining lines.

    thank you very much for your help.

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Excel/VBA - Clicking checklist (HTML). Why not work?

    You haven't made the changes I suggested.

    What is it you actually want to do?

    Click to go to the next page or change the no of results that will appear on the the page?

    This code will goto the next page.
    Set obj2 = ie.document.getelementbyid("tblScheduleData_next")
        
        obj2.Click

  7. #7
    Registered User
    Join Date
    08-28-2012
    Location
    Brazil
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Excel/VBA - Clicking checklist (HTML). Why not work?

    I want to:

    1 - Select "100" on the checklist;
    2 - Download the "100" lines;
    3 - Click on "Next" (page2)
    4 - Download the lines that are on page 2

    The code to click "next" worked, but the code to select "100" on the checklist did not work.

    thank you very much for your help.

  8. #8
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Excel/VBA - Clicking checklist (HTML). Why not work?

    I didn't post code to select 100 from the checklist.

    I posted code to find the checklist - what you do with it then is up to you really.

  9. #9
    Registered User
    Join Date
    08-28-2012
    Location
    Brazil
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Excel/VBA - Clicking checklist (HTML). Why not work?

    OK. Thank you very much for your help.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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