Import Excel into Access table.

C

Cyndy Grover

I need help on coding with vba away to import an Excel
spreadsheet into a temporary table,then run a append query
to get the data into the main table, then delete temporary
table all using vba.
 
G

Guest

-----Original Message-----
I need help on coding with vba away to import an Excel
spreadsheet into a temporary table,then run a append query
to get the data into the main table, then delete temporary
table all using vba.
.
sub imp excel()
Set db = CurrentDB()

DoCmd.TransferSpreadsheet acImport,
acSpreadsheetTypeExcel9, "tablename", "excel file path&
file name", True, "name of worksheet!"
docmd.runsql "INSERT INTO MAIN TABLE SELECT TEMPTABLE.*
FROM TEMPTABLE;
db.tabledefs.Delete "TEMPTALE"
end sub
 
J

Jamie Collins

sub imp excel()
Set db = CurrentDB()

DoCmd.TransferSpreadsheet acImport,
acSpreadsheetTypeExcel9, "tablename", "excel file path&
file name", True, "name of worksheet!"
docmd.runsql "INSERT INTO MAIN TABLE SELECT TEMPTABLE.*
FROM TEMPTABLE;
db.tabledefs.Delete "TEMPTALE"
end sub

Simpler:

INSERT INTO
MAIN_TABLE
SELECT
*
FROM
[Excel 8.0;HDR=YES;C:\excel_path\excel_file.xls;].[name_of_worksheet$]
;

but with the column list specified, of course.

Jamie.

--
 
C

Cyndy Grover

Thank You
-----Original Message-----

sub imp excel()
Set db = CurrentDB()

DoCmd.TransferSpreadsheet acImport,
acSpreadsheetTypeExcel9, "tablename", "excel file path&
file name", True, "name of worksheet!"
docmd.runsql "INSERT INTO MAIN TABLE SELECT TEMPTABLE.*
FROM TEMPTABLE;
db.tabledefs.Delete "TEMPTALE"
end sub




.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top