title: VBA to transfer inner text from html page to excel
body: <p><strong>This image shows what I use the following macro</strong><br>
  <a href="https://i.stack.imgur.com/n4YHi.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/n4YHi.png" alt="enter image description here"></a></p>
  
  <p>But this code stops after the opening of two or three URLs and we see the following error message,<br>
  1.  run-time err  91<br>
  2.  object variable or with block not set<br></p>
  
  <pre><code>Sub test()
  
  Dim wb As Object
  Dim doc As Object
  Dim sURL As String
  Dim lastrow As Long
  Dim n As Integer
  Dim i As Integer
  Dim HtmlToText As String
  Dim result
  lastrow = Sheet1.Cells(Rows.Count, "A").End(xlUp).Row
  
  For i = 2 To lastrow  'Start the loop on the second row of column A. Until the last URL..
  
      Set wb = CreateObject("internetExplorer.Application")
      sURL = Cells(i, 1)
      wb.navigate sURL
      wb.Visible = False
      While wb.Busy
        DoEvents
      Wend
      'HTML document
      Set doc = wb.document
      Dim Name As Variant
      Dim Posts As Variant
      Dim Followers As Variant
      Dim Following As Variant
      Dim DivValue As Variant
      Dim DivValueSplit As Variant
      Dim DivValueResult As Variant
      Dim Biography As Variant
  
      Name = doc.getElementsByClassName("AC5d8 notranslate")(0).innerText
      Posts = doc.getElementsByClassName("g47SY")(0).innerText
      Followers = doc.getElementsByClassName("g47SY")(1).innerText
      Following = doc.getElementsByClassName("g47SY")(2).innerText
      'dd = web.document.querySelector("div.-vDIg span").innerText
      DivValue = doc.getElementsByClassName("-vDIg")(0).innerText
  
      'DivValueSplit = Split(DivValue, "&lt;br&gt;")
      'If UBound(DivValueSplit) = 2 Then
      '   DivValueResult = DivValueSplit(1) &amp; DivValueSplit(2)
       '  j = InStr(DivValueResult, "&lt;/span&gt;")
        ' Biography = Mid(DivValueResult, 7, j - 7)
      'ElseIf sURL = "https://www.instagram.com/philipplein/" Then
       ' DivValueResult = DivValueSplit(0)
        'j = InStr(DivValueResult, "&lt;/h1&gt;")
        'Biography = Mid(DivValueResult, 19, j - 5)
      'Else
       '   DivValueResult = DivValueSplit(1)
        '  j = InStr(DivValueResult, "&lt;/span&gt;")
         ' Biography = Mid(DivValueResult, 7, j - 7)
      'End If
  
      Worksheets("sheet1").Cells(i, 2) = Name
      Worksheets("sheet1").Cells(i, 3) = Followers
      Worksheets("sheet1").Cells(i, 4) = Following
      Worksheets("sheet1").Cells(i, 5) = Posts
      Worksheets("sheet1").Cells(i, 6) = DivValue
      'Biography = Replace(re1, "&lt;span&gt;", "")
  
      'Cells(i, 2) = HtmlToText
      ' myarray = Split(Data, vbCrLf)
  err_clear:
  
  
  
        If Err &lt;&gt; 0 Then
            Err.Clear
            Resume Next
          End If
          wb.Quit
      Next i
  
  End Sub
  </code></pre>