Option Compare Database
Option Explicit
Dim objXL As Object
Dim sTable, xlPath As String, i As Integer
Public sub ImportExcelSheets()
Call ImportSheetsYears1
Call ImportSheetsYears2
Call ImportSheetsYears3
End Sub
Private Sub ImportSheetsYears1()
xlPath = "\\serverName\Year1.xlsx"
Set objXL = CreateObject("Excel.Application")
objXL.Workbooks.Open xlPath, , True
With objXL
For i = 1 To .Worksheets.Count
If InStr(.Worksheets(i).Name, "widget") Then
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel12, _
"tableName", xlPath, True, .Worksheets(i).Name & "!A:M"
End If
Next
End With
objXL.Quit
Set objXL = Nothing
End Sub
Private Sub ImportSheetsYears2()
xlPath = "\\serverName\Year2.xlsx"
Set objXL = CreateObject("Excel.Application")
objXL.Workbooks.Open xlPath, , True
With objXL
For i = 1 To .Worksheets.Count
If InStr(.Worksheets(i).Name, "widget") Then
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel12, _
"tableName", xlPath, True, .Worksheets(i).Name & "!A:M"
End If
Next
End With
objXL.Quit
Set objXL = Nothing
End Sub
Private Sub ImportSheetsYears3()
xlPath = "\\serverName\Year3.xlsx"
Set objXL = CreateObject("Excel.Application")
objXL.Workbooks.Open xlPath, , True
With objXL
For i = 1 To .Worksheets.Count
If InStr(.Worksheets(i).Name, "widget") Then
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel12, _
"tableName", xlPath, True, .Worksheets(i).Name & "!A:M"
End If
Next
End With
objXL.Quit
Set objXL = Nothing
End Sub
|