title: VBA: click on next button on a website (loop)
body: <p>I'm trying to get info from a website with many pages. I already got the extraction of the information, however I can't perform a loop to click the &quot;next page&quot; button and do it again..</p>
  <p>Can you please help me?</p>
  <p>Thanks,
  M</p>
  <pre><code>Sub website_test()
  
  Dim ie As Object
  Dim ht As HTMLDocument
  Dim button As Object
  Dim i As Integer
  
  For i = 0 To 100
  
  Set ie = CreateObject(&quot;InternetExplorer.Application&quot;)
  ie.Visible = True
  
  ie.navigate (&quot;https://old.reddit.com/r/fashion/new/&quot;)
  
  Do Until ie.readyState = 4
     DoEvents
  Loop
      
  Set ht = ie.document
  
  Set elems = ht.getElementsByClassName(&quot;title may-blank&quot;)
  
  For Each elem In elems
      Debug.Print (elem.innerText)
      Next
  
  Set button = ht.getElementsByTagName(&quot;nofollow next&quot;)
  
  button(i + 1).Click --&gt; **is this where it gets an error (run-time error 91: object variable or width block variable not set)**
  
  Next i
      
  End Sub
  </code></pre>