title: Object variable or With block variable not set (Error 91)
body: <p>I have the following code:</p>
  
  <pre><code>Sub AddSources()
      Dim pubPage As Page
      Dim pubShape As Shape
      Dim hprlink As Hyperlink
      Dim origAddress() As String
      Dim exportFileName As String
      exportFileName = "TestResume"
      Dim linkSource As String
      linkSource = "TestSource2"
      Dim hyperLinkText As TextRange
  
  
  
      For Each pubPage In ActiveDocument.Pages
          For Each pubShape In pubPage.Shapes
              If pubShape.Type = pbTextFrame Then
                  For Each hprlink In pubShape.TextFrame.TextRange.Hyperlinks
                      If InStr(hprlink.Address, "http://bleaney.ca") &gt; 0 Then
                          hyperLinkText = hprlink.Range
                          origAddress = Split(hprlink.Address, "?source=")
                          hprlink.Address = origAddress(0) + "?source=" + linkSource
                          hprlink.Range = hyperLinkText
                      End If
                  Next hprlink
              End If
          Next pubShape
      Next pubPage
      ThisDocument.ExportAsFixedFormat pbFixedFormatTypePDF, "C:\" + exportFileName + ".pdf"
  End Sub
  </code></pre>
  
  <p>I am getting the "Object variable or With block variable not set (Error 91)" error on the line with <code>hyperLinkText = hprlink.Range</code>. When I debug I can see that <code>hprlink.Range</code> does have a value. Any thoughts what I'm doing wrong?</p>