<font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> allExcelSheetsBooks()<br><SPAN style="color:#007F00">'Copy this code into a module in Access</SPAN><br><SPAN style="color:#007F00">'Open the database then use Alt + F11</SPAN><br><SPAN style="color:#007F00">'Select the Insert menu and Module</SPAN><br><br><SPAN style="color:#00007F">Dim</SPAN> blnHasFieldNames <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Boolean</SPAN>, blnEXCEL <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Boolean</SPAN>, blnReadOnly <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Boolean</SPAN><br><SPAN style="color:#00007F">Dim</SPAN> lngCount <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN><br><SPAN style="color:#00007F">Dim</SPAN> objExcel <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Object</SPAN>, objWorkbook <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Object</SPAN><br><SPAN style="color:#00007F">Dim</SPAN> colWorksheets <SPAN style="color:#00007F">As</SPAN> Collection<br><SPAN style="color:#00007F">Dim</SPAN> strPathFile <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN><br><SPAN style="color:#00007F">Dim</SPAN> strPassword <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN><br><br><SPAN style="color:#007F00">' Establish an EXCEL application object</SPAN><br><SPAN style="color:#00007F">On</SPAN> <SPAN style="color:#00007F">Error</SPAN> <SPAN style="color:#00007F">Resume</SPAN> <SPAN style="color:#00007F">Next</SPAN><br><SPAN style="color:#00007F">Set</SPAN> objExcel = GetObject(, "Excel.Application")<br><SPAN style="color:#00007F">If</SPAN> Err.Number <> 0 <SPAN style="color:#00007F">Then</SPAN><br> <SPAN style="color:#00007F">Set</SPAN> objExcel = CreateObject("Excel.Application")<br> blnEXCEL = <SPAN style="color:#00007F">True</SPAN><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br>Err.Clear<br><SPAN style="color:#00007F">On</SPAN> <SPAN style="color:#00007F">Error</SPAN> <SPAN style="color:#00007F">GoTo</SPAN> 0<br><br><SPAN style="color:#007F00">' Change this next line to True if the first row in EXCEL worksheet</SPAN><br><SPAN style="color:#007F00">' has field names</SPAN><br>blnHasFieldNames = <SPAN style="color:#00007F">True</SPAN><br><br><SPAN style="color:#007F00">' Replace C:\Filename.xls with the actual path and filename</SPAN><br>strPathFile = "M:\access files\tblStaff Import.xls"<br><br><SPAN style="color:#007F00">' Replace passwordtext with the real password;</SPAN><br><SPAN style="color:#007F00">' if there is no password, replace it with vbNullString constant</SPAN><br><SPAN style="color:#007F00">' (e.g., strPassword = vbNullString)</SPAN><br>strPassword = vbNullString<br><br>blnReadOnly = <SPAN style="color:#00007F">True</SPAN> <SPAN style="color:#007F00">' open EXCEL file in read-only mode</SPAN><br><br><SPAN style="color:#007F00">' Open the EXCEL file and read the worksheet names into a collection</SPAN><br><SPAN style="color:#00007F">Set</SPAN> colWorksheets = <SPAN style="color:#00007F">New</SPAN> Collection<br><SPAN style="color:#00007F">Set</SPAN> objWorkbook = objExcel.Workbooks.Open(strPathFile, , blnReadOnly, , _<br> strPassword)<br><SPAN style="color:#00007F">For</SPAN> lngCount = 1 <SPAN style="color:#00007F">To</SPAN> objWorkbook.Worksheets.Count<br> colWorksheets.Add objWorkbook.Worksheets(lngCount).Name<br><SPAN style="color:#00007F">Next</SPAN> lngCount<br><br><SPAN style="color:#007F00">' Close the EXCEL file without saving the file, and clean up the EXCEL objects</SPAN><br>objWorkbook.Close <SPAN style="color:#00007F">False</SPAN><br><SPAN style="color:#00007F">Set</SPAN> objWorkbook = <SPAN style="color:#00007F">Nothing</SPAN><br><SPAN style="color:#00007F">If</SPAN> blnEXCEL = <SPAN style="color:#00007F">True</SPAN> <SPAN style="color:#00007F">Then</SPAN> objExcel.Quit<br><SPAN style="color:#00007F">Set</SPAN> objExcel = <SPAN style="color:#00007F">Nothing</SPAN><br><br><SPAN style="color:#007F00">' Import the data from each worksheet into a separate table</SPAN><br><SPAN style="color:#00007F">For</SPAN> lngCount = colWorksheets.Count <SPAN style="color:#00007F">To</SPAN> 1 <SPAN style="color:#00007F">Step</SPAN> -1<br> DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, _<br> "tbl" & colWorksheets(lngCount), strPathFile, blnHasFieldNames, _<br> colWorksheets(lngCount) & "$"<br><SPAN style="color:#00007F">Next</SPAN> lngCount<br><br><SPAN style="color:#007F00">' Delete the collection</SPAN><br><SPAN style="color:#00007F">Set</SPAN> colWorksheets = <SPAN style="color:#00007F">Nothing</SPAN><br><br><SPAN style="color:#007F00">' Uncomment out the next code step if you want to delete the</SPAN><br><SPAN style="color:#007F00">' EXCEL file after it's been imported</SPAN><br><SPAN style="color:#007F00">' Kill strPathFile</SPAN><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br><br></FONT>