P
Problem Importing >1 Excel Worksheet 1 Excel Wor
I tried using the script from a January 2008 Scripting Guy posting. It is
supposed to import multiple worksheets from an Excel workbook into an Access
table. My test Excel workbook has 2 worksheets. The first worksheet gets
imported but the second worksheet does not.
Any advice?
Steve
Const acImport = 0
Const acSpreadsheetTypeExcel9 = 8
Set objAccess = CreateObject("Access.Application")
objAccess.OpenCurrentDatabase "C:\Scripts\Personnel.mdb"
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
strFileName = "C:\Scripts\ImportData.xls"
Set objWorkbook = objExcel.Workbooks.Open(strFileName)
Set colWorksheets = objWorkbook.Worksheets
For Each objWorksheet in colWorksheets
Set objRange = objWorksheet.UsedRange
strWorksheetName = objWorksheet.Name & "!" & objRange.Address(False,
False)
objAccess.DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, _
"Employees", strFileName, True, strWorksheetName
Next
supposed to import multiple worksheets from an Excel workbook into an Access
table. My test Excel workbook has 2 worksheets. The first worksheet gets
imported but the second worksheet does not.
Any advice?
Steve
Const acImport = 0
Const acSpreadsheetTypeExcel9 = 8
Set objAccess = CreateObject("Access.Application")
objAccess.OpenCurrentDatabase "C:\Scripts\Personnel.mdb"
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
strFileName = "C:\Scripts\ImportData.xls"
Set objWorkbook = objExcel.Workbooks.Open(strFileName)
Set colWorksheets = objWorkbook.Worksheets
For Each objWorksheet in colWorksheets
Set objRange = objWorksheet.UsedRange
strWorksheetName = objWorksheet.Name & "!" & objRange.Address(False,
False)
objAccess.DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, _
"Employees", strFileName, True, strWorksheetName
Next