title: Import an Excel worksheet into Access using VBA
body: <p>I am attempting to import an Excel spreadsheet into Access using some simple VBA code. The issue I have run into is there are 2 worksheets in the Excel file, and I need the 2nd worksheet to be imported. Is it possible to specify the needed worksheet in the VBA code? </p>
  
  
  
  <pre class="lang-vb prettyprint-override"><code>Private Sub Command0_Click()
  
  Dim dlg As FileDialog
  Set dlg = Application.FileDialog(msoFileDialogFilePicker)
  
  With dlg
  .Title = "Select the Excel file to import"
  .AllowMultiSelect = False
  .Filters.Clear
  .Filters.Add "Excel Files", "*.xls", 1
  .Filters.Add "All Files", "*.*", 2
  
  If .Show = -1 Then
  StrFileName = .SelectedItems(1)
  DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel8, "COR Daily", StrFileName, True
  Else
  Exit Sub
  End If
  End With
  
  End Sub
  </code></pre>
  
  <p>Should I set StrFileName to <code>'StrFileName'&amp;'.Worksheetname'</code> ? Is that the proper naming scheme for that?</p>
  
  <p>something like:</p>
  
  <pre class="lang-vb prettyprint-override"><code>StrFileName = StrFileName &amp; ".WorkSheetName"
  </code></pre>