Public Sub ImportExcelSheetsfIANL()
Dim objXL As Object
Dim sTable, xlPath As String, i As Integer
Dim myPath(), j, iCnt As Integer
myPath = Array("\\server\Year1.xlsx", _
"\\server\Year2.xlsx", _
"\\server\Year3.xlsx")
For j = LBound(myPath) To UBound(myPath)
If Dir(myPath(j)) <> "" Then
Set objXL = CreateObject("Excel.Application")
objXL.Workbooks.Open myPath(j), , True
With objXL
For i = 1 To .Worksheets.Count
If InStr(.Worksheets(i).Name, "widget") Then
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel12, _
"tblMaster", myPath(j), True, .Worksheets(i).Name & "!A:M"
End If
Next
End With
objXL.Quit
Set objXL = Nothing
Else
iCnt = iCnt + 1
End If
Next
If iCnt = 3 Then
MsgBox "Worksheets do not exist. Exiting sub now!", vbInformation, "Error"
Exit Sub
End If
|