title: Access VBA - Function to create an array with the names of all the worksheets of a selected excel workbook
body: <p>I am using Access trying to upload all the worksheets of an excel (which I select) as table to the Database.<br />
  To do so, I am creating a function that I recall in my procedure; this function should read the names of the worksheets in my excel file and save them in an array/collection (which one do you suggests? the number of worksheets is not fixed). This is my code for the moment but it doesn't work properly because I find in my array only the last worksheet and not all the previous ones:</p>
  <pre><code>Function Get_Sheetsname_Array(xlsfile)
      Dim sheetsLst As Collection
      Dim lookupWB As Excel.Application
      Dim txt As String
      
      Set lookupWB = New Excel.Application
      lookupWB.Workbooks.Open xlsfile
      
      toIndex = lookupWB.Worksheets.Count
      
      Dim i As Integer
      
      With lookupWB
          For Each wrksheet In .Worksheets
              sheetsLst = Array(.xlSheet.Name)
          Next wrksheet
      End With
  
  
      Get_Sheetsname_Array = sheetLst
      
  End Function
  </code></pre>