title: RunTime Error 91; Transferring Data from Excel to Word Table
body: <p>I am having trouble with what seems to be something simple from what I have found so far. I am trying to link data from an excel workbook to a table on a word document through VBA. This is the code that I have found and changed slightly so far...</p>
  
  <pre><code>Sub GetData()
      Dim strPath As String
      Dim strFileName As String
      Dim strFileExtension As String
      Dim strFullName As String
  
      strPath = "file path here"
      strFileName = "file name here"
      strFileExtension = "Extension here"
      strFullName = strPath &amp; strFileName &amp; strFileExtension
  
      Set objWorkbook = objExcel.Workbooks.Open(strFullName)
  
      'Set the text of the cell from Excel to the cell in the specified table in 
      'Word (the second table in this instance)   
  
      ActiveDocument.Tables(1).Cell(2, 2).Range.Text =  objWorkbook.Sheets("Sheet1") _
          .Cells(2, 1)
  
      'Close Excel bits
      objWorkbook.Close
  
      Set objWorkbook = Nothing
  End Sub
  </code></pre>
  
  <p>The initial errors I had found were not having the excel object library checked off in References and simple syntax errors. After fixing those I am now getting a 'RunTime Error 91 Object Variable or With Block Variable not set'. This error occurs when I am attempting to set the objWorkbook variable. I have these public variable declared...</p>
  
  <pre><code>Public objExcel As Excel.Application
  Public objWorkbook As Excel.Workbook
  Public objWorksheet As Excel.Worksheet
  Public objRange As Excel.Range
  </code></pre>
  
  <p>However, when I look up this error, all I find is that I need to declare these public variables. Not sure where to go from here. If anyone could push me in the right direction, that would be greatly appreciated. Also, thank you for all the help so far, this website is a life saver.</p>