title: VBA - Retrieving Data from Closed Excel Workbook
body: <p>I am trying to create a VBA script that will gather data from four different Workbooks.  For now, I am just testing the code with one Workbook, but I am receiving an error when I try to acquire the data.  While I would like to retrieve the data from the four Workbooks without opening them, I will need to open them in order to find the last row of data.  Here is my current code:</p>
  
  <pre><code>Public Sub GetData()
  
  Application.ScreenUpdating = False
  
  Dim LastRow As Integer
  Dim WB As Workbook
  Dim xlsPath As String
  Dim xlsFilename As String
  Dim SheetName As String
  
  xlsPath = "C:\Users\a27qewt\My Documents\Document Retention\FI_DocumentRetention.xlsm"
  
  Set WB = Workbooks.Open(xlsPath)
  
  'Workbooks("FI_DocumentRetention.xlsm").Sheets("S&amp;S Document Locations").Unprotect
  
  LastRow = Workbooks("FI_DocumentRetention.xlsm").Sheets("S&amp;S Document Locations").Cells(Rows.Count, "A").End(xlUp).Row
  
  Workbooks("SS_Index.xlsm").Sheets("Document Index").Range(Cells(2, 1), Cells(LastRow, 5)).Value = _
  Workbooks("FI_DocumentRetention.xlsm").Sheets("S&amp;S Document Locations").Range(Cells(2, 1), Cells(LastRow, 5)).Value
  
  WB.Close False
  
  End Sub
  </code></pre>
  
  <p>I am receiving a 1004 application/object defined error in the <code>Workbooks("FI_DocumentRetention.xlsm").Sheets("S&amp;S Document Locations").Range</code>... line.  Any suggestions why?</p>