VBA_Excel Into Access
Question:
Answers:
I am trying to use VBA to import an excel file (which I have on a local drive) into Microsoft Access.
Currently this is the code that I have, but I know that it is incorrect:
Currently this is the code that I have, but I know that it is incorrect:
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel12Xml, "example", selectFile, True
Can someone please help?Answers:
The complete template for a spreadsheet transfer is as such:
TableName would be the name of the table in the Access database that you're importing your spreadsheet into, FileName is the name (including the full path) of the file you're importing. HasFieldNames refers to whether or not the first row in your spreadsheet contains field names or not. Range would be used if you intended to only import a specific range from your spreadsheet, and UseOA is no longer supported.
Since you give no specific information as to your file name, table name or anything else, all I can offer is this "example" code. You will have to replace your information in it yourself. Note that Range is optional, if you don't want to input a specific range then simply delete that piece.
expression.TransferSpreadsheet(TransferType, SpreadsheetType, TableName, _
FileName, HasFieldNames, Range, UseOA)
where TransferType, in your case, is acImport and SpreadsheetType is acSpreadsheetTypeExcel12Xml (assuming it is, in fact, an Office 2010 XML file).TableName would be the name of the table in the Access database that you're importing your spreadsheet into, FileName is the name (including the full path) of the file you're importing. HasFieldNames refers to whether or not the first row in your spreadsheet contains field names or not. Range would be used if you intended to only import a specific range from your spreadsheet, and UseOA is no longer supported.
Since you give no specific information as to your file name, table name or anything else, all I can offer is this "example" code. You will have to replace your information in it yourself. Note that Range is optional, if you don't want to input a specific range then simply delete that piece.
DoCmd.TransferSpreadsheet acImport, 10, "MyTableName", _
"C:\MyDocuments\MyFile.xls", True, "A1:G12"
Note that SpreadsheetType can use a numerical value instead of the full text value, both are acceptable.
Commentaires
Enregistrer un commentaire