vba 使用VB6将数据从Excel文件传输到Access文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3865540/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Transfer data from Excel file to Access File using VB6
提问by guest1
Dear All, I have an excel file (.xls) with data in the first Sheet that is named "Customers". I also have an Access.mdb database that contains a table called " CustomerDetails". I would like to transfer the data from the excel sheet into the Access database using VB6 code. How can I do that? Thanks in advance,
亲爱的所有人,我有一个 excel 文件 (.xls),其中第一个名为“Customers”的工作表中有数据。我还有一个 Access.mdb 数据库,其中包含一个名为“CustomerDetails”的表。我想使用 VB6 代码将 Excel 工作表中的数据传输到 Access 数据库中。我怎样才能做到这一点?提前致谢,
回答by ImadArif
回答by Beth
Can you use Access to import the worksheet from Excel?
您可以使用 Access 从 Excel 导入工作表吗?
If not, and you need to do it in VB, you'll need to either open the Excel file in VB or export from Excel to a csv format and open that, then write the data to an existing Access table.
如果没有,并且您需要在 VB 中执行此操作,则需要在 VB 中打开 Excel 文件或从 Excel 导出为 csv 格式并打开它,然后将数据写入现有的 Access 表。
回答by Waller
this is quite simple to do, just place the below code in a module in Access and this will import it for you automatically. If you need the code to run you can place it in the form_open or something similar. You could even start it up with a batch file.
这很简单,只需将以下代码放在 Access 的模块中,它就会自动为您导入。如果您需要运行代码,您可以将它放在 form_open 或类似的东西中。您甚至可以使用批处理文件启动它。
Function import()
basedir = "INSERT YOUR SPREADSHEET HERE"
DoCmd.TransferSpreadsheet _
acImport, _
acSpreadsheetTypeExcel9, _
"TABLE NAME HERE", _
basedir, _
False
End Function