thomasd04
asked on
Import thousands of worksheet columns into Access table
I have a Excell Spreadsheet that has over 5,000 worksheets. Each worksheet has the same exact number of column and column names; and each worksheet has at least one row of data. I'm currently using the following VB code to import but it is extremely, extremely slow:
(Excel and Access 2007)
Const acImport = 0
Const acSpreadsheetTypeExcel9 = 8
Set objAccess = CreateObject("Access.Application")
objAccess.OpenCurrentDatabase "C:\SomeFolder\data.accdb"
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
strFileName = "C:\SomeFile\File.xlsx"
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, _
"Vulnerability", strFileName, True, strWorksheetName
Next
Does anyone know a faster or more effecient way to get this done?(Excel and Access 2007)
ASKER
Hi HainKurt. I'm not quite sure what you are suggestion. Could you clarify a bit more? Right now the spreadsheet is being created by an external application and we are unable to modify how it outputs to Excel. Now that it's been outputted in this format, I need to find a way to get it into a database.
what I say is, instead of loading each worksheet into db one by one,
create a new excel file with one worksheet
then with vba code, collect all data from worksheets and put into the new excel file (add a new column to store worksheetname)
then load this worksheet into db in one shot...
create a new excel file with one worksheet
then with vba code, collect all data from worksheets and put into the new excel file (add a new column to store worksheetname)
then load this worksheet into db in one shot...
ASKER
ahhhh...okay. That makes sense. Could you help me with the code? I'm not good with VB, it took me forever to write the little code I posted above.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
then load all data to db in one shot!