简体   繁体   English

使用VB6将数据从Excel文件传输到Access文件

[英]Transfer data from Excel file to Access File using VB6

Dear All, I have an excel file (.xls) with data in the first Sheet that is named "Customers". 亲爱的所有人,我有一个Excel文件(.xls),其中包含名为“客户”的第一张工作表中的数据。 I also have an Access.mdb database that contains a table called " CustomerDetails". 我也有一个Access.mdb数据库,其中包含一个名为“ CustomerDetails”的表。 I would like to transfer the data from the excel sheet into the Access database using VB6 code. 我想使用VB6代码将数据从excel工作表传输到Access数据库。 How can I do that? 我怎样才能做到这一点? Thanks in advance, 提前致谢,

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表中。

this is quite simple to do, just place the below code in a module in Access and this will import it for you automatically. 这很简单,只需将下面的代码放在Access中的模块中,这将自动为您导入。 If you need the code to run you can place it in the form_open or something similar. 如果您需要运行代码,可以将其放在form_open或类似的名称中。 You could even start it up with a batch file. 您甚至可以使用批处理文件启动它。

Function import()

basedir = "INSERT YOUR SPREADSHEET HERE"

DoCmd.TransferSpreadsheet _
            acImport, _
            acSpreadsheetTypeExcel9, _
            "TABLE NAME HERE", _
            basedir, _
            False
End Function

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM