简体   繁体   English

任何人都知道如何在没有下一个按钮时停止宏(Excel VBA)

[英]Anyone know how to get macro (Excel VBA) to stop when there is no next button

Anyone know how to get a macro (Excel VBA) to stop when there is no next button present (so it should scrape x pages until next button value is no longer present). 任何人都知道如何在没有下一个按钮时停止宏(Excel VBA)(因此它应该刮取x页直到下一个按钮值不再存在)。

Any help? 有帮助吗? Loop Until e.Value <> "Next Results" 循环直到e.Value <>“下一个结果”

Sub Test()

       Dim ie As Object
       Dim i As Long
       Dim strText As String
       Dim doc As Object
       Dim hTable As Object
       Dim hBody As Object
       Dim hTR As Object
       Dim hTD As Object
       Dim tb As Object
       Dim bb As Object
       Dim tr As Object
       Dim td As Object

       Dim y As Long, z As Long, wb As Excel.Workbook, ws As Excel.Worksheet

         Set wb = Excel.ActiveWorkbook
         Set ws = wb.ActiveSheet

         Set ie = CreateObject("InternetExplorer.Application")
         ie.Visible = True

         y = 1   'Column A in Excel
         z = 1   'Row 1 in Excel
    variable = 0
    Here:

         ie.navigate "http://games.espn.com/ffl/tools/projections?&seasonTotals=true&seasonId=2016&slotCategoryId=0&startIndex=" & variable

         Do While ie.Busy: DoEvents: Loop
         Do While ie.ReadyState <> 4: DoEvents: Loop

         Set doc = ie.document
         Set hTable = doc.getElementsByClassName("playerTableTable tableBody")

         For Each tb In hTable

            Set hBody = tb.getElementsByTagName("tbody")
            For Each bb In hBody

                Set hTR = bb.getElementsByTagName("tr")
                For Each tr In hTR

                     Set hTD = tr.getElementsByTagName("td")
                     y = 1 ' Resets back to column A
                     For Each td In hTD
                       ws.Cells(z, y).Value = td.innerText
                       y = y + 1
                     Next td
                     DoEvents
                     z = z + 1
                Next tr
                Exit For
            Next bb
        Exit For
      Next tb

    variable = variable + 40
    GoTo Here:


      End Sub

I read somewhere that adding (below) might help though its as yet to work for me. 我在某个地方读到添加(下面)可能会有所帮助,尽管它还没有为我工作。

buttonFound = True
While buttonFound

Set allLinks = ie.getElementsByTagName("a")
buttonFound = False
For Each btn In allLinks
    If btn.innerText = "Next"
        buttonFound = True
        Set btnNext = btn
        Exit For
    End If
Next btn

btn.Click
End Sub

Try this: 尝试这个:

' FindNextButton()
Set allLinks = ie.getElementsByTagName("a")
For Each btn In allLinks
    If btn.innerText = "Next"
        btn.Click
        Goto Here
        Exit For
    End If
Next btn

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM