The closest method to the functionality of the Import Spreadsheet wizard is the TransferSpreadsheet
method of the DoCmd
object.
However, whilst you can specify whether the first row of the spreadsheet contains field names, you cannot supply an import specification (as you might with the TransferText
method), and so you cannot control the data types & indexing of each column, nor whether specific columns should be ignored by the import.
Possible alternatives might be to initially import the spreadsheet using the TransferSpreadsheet
method, and then insert the imported data into a pre-existing table with the appropriate fields & indexing options configured as you require, e.g.:
insert into
myexistingtable ( field1, field2, field3 ... )
select
myimportedtable.column1, myimportedtable.column2, myimportedtable.column3 ...
from
myimportedtable
Alternatively, you could bypass the TransferSpreadsheet
method import and access the data held by the spreadsheet directly using ADO, e.g.:
insert into
myexistingtable ( field1, field2, field3 ... )
select
myimportedtable.column1, myimportedtable.column2, myimportedtable.column3 ...
from
[Excel 12.0 Xml;HDR=Yes;Database=C:\YourExcelFile.xlsx].[YourSheet$A:Z]