[Solved] VBA for Import Mulitple Worksheets from Same Workbook
Hello..
I am trying to set up VBA to import a user selected Excel workbook that contains various numbers of variously named worksheets that are all formatted the same. I do not care about the worksheet names, but need to import them all into the same Access table. Each worksheet contains extraneous header information that I cannot remove. Here is the code that I have that works but only does so for the first worksheet in the workbook. I need to get it to iterate through the same cell range in all worksheets in the workbook. My Access table for the data to be loaded into is Import_Temp. Any help would be appreciated.
Private Sub Command0_Click()
Dim fileName As Variant
Dim strFileName As String
Call Application.FileDialog(msoFileDialogOpen).Filters.Clear
'Add a custom filter
Call Application.FileDialog(msoFileDialogOpen).Filters.Add( _
"Excel XLSX Files Only", "*.xlsx")
Set fileName = Application.FileDialog(msoFileDialogOpen)
If fileName.Show Then
strFileName = fileName.SelectedItems(1)
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel12, "Import_Temp", strFileName, True, "A3:V66"
End If
End Sub
Hello..
I am trying to set up VBA to import a user selected Excel workbook that contains various numbers of variously named worksheets that are all formatted the same. I do not care about the worksheet names, but need to import them all into the same Access table. Each worksheet contains extraneous header information that I cannot remove. Here is the code that I have that works but only does so for the first worksheet in the workbook. I need to get it to iterate through the same cell range in all worksheets in the workbook. My Access table for the data to be loaded into is Import_Temp. Any help would be appreciated.
Private Sub Command0_Click()
Dim fileName As Variant
Dim strFileName As String
Call Application.FileDialog(msoFileDialogOpen).Filters.Clear
'Add a custom filter
Call Application.FileDialog(msoFileDialogOpen).Filters.Add( _
"Excel XLSX Files Only", "*.xlsx")
Set fileName = Application.FileDialog(msoFileDialogOpen)
If fileName.Show Then
strFileName = fileName.SelectedItems(1)
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel12, "Import_Temp", strFileName, True, "A3:V66"
End If
End Sub
Last edited: