I am trying to import an Excel spreadsheet into Access using simple VBA code. The problem I ran into is that there are 2 sheets in the Excel file and I need a second sheet that needs to be imported. Is it possible to specify the required sheet in VBA 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
Should I set StrFileName to 'StrFileName'&'.Worksheetname' ? Is this the correct naming scheme for this?
sort of:
StrFileName = StrFileName & ".WorkSheetName"
source share