DoCmd.TransferSpreadsheet 方法 (Access)DoCmd.TransferSpreadsheet method (Access)

在 Visual Basic 中,TransferSpreadsheet 方法执行 TransferSpreadsheet 操作。The TransferSpreadsheet method carries out the TransferSpreadsheet action in Visual Basic.

语法Syntax

expression.TransferSpreadsheet (TransferType, SpreadsheetType, TableName, FileName, HasFieldNames, Range, UseOA)expression.TransferSpreadsheet (TransferType, SpreadsheetType, TableName, FileName, HasFieldNames, Range, UseOA)

expression:表示 DoCmd 对象的变量。expression A variable that represents a DoCmd object.

参数Parameters

名称Name 必需/可选Required/Optional 数据类型Data type 说明Description
TransferTypeTransferType 可选Optional AcDataTransferTypeAcDataTransferType 你想要执行的传输类型。The type of transfer that you want to make. 默认值为 acImportThe default value is acImport.
SpreadsheetTypeSpreadsheetType 可选Optional AcSpreadSheetTypeAcSpreadSheetType 用于指明所要从中导入、导出到或链接到的电子表格的类型。The type of spreadsheet to import from, export to, or link to.
TableNameTableName 可选Optional VariantVariant 字符串表达式,表示要向其中导入电子表格数据、从中导出电子表格数据或将电子表格数据链接到的 Office Access 表名称,或要将其结果导出到电子表格的 Access 选择查询名称。A string expression that is the name of the Office Access table that you want to import spreadsheet data into, export spreadsheet data from, or link spreadsheet data to, or the Access select query whose results you want to export to a spreadsheet.
FileNameFileName 可选Optional VariantVariant 字符串表达式,表示要导入其中数据、将数据导出到其中或将数据链接到其中的电子表格的文件名和路径。A string expression that's the file name and path of the spreadsheet that you want to import from, export to, or link to.
HasFieldNamesHasFieldNames 可选Optional VariantVariant 如果指定 True (1),可以在导入或链接时将电子表格的第一行用作字段名称。Use True (1) to use the first row of the spreadsheet as field names when importing or linking. 如果指定 False (0),可以将电子表格的第一行视为普通数据。Use False (0) to treat the first row of the spreadsheet as normal data. 如果将此参数留空,假设使用的是默认值 (False)。If you leave this argument blank, the default (False) is assumed. 将 Access 表或选择查询数据导出到电子表格时,无论为此参数输入的值是什么,字段名称都会插入电子表格的第一行。When you export Access table or select query data to a spreadsheet, the field names are inserted into the first row of the spreadsheet no matter what you enter for this argument.
RangeRange 可选Optional VariantVariant 字符串表达式,表示电子表格中有效的单元格区域或区域名称。A string expression that's a valid range of cells or the name of a range in the spreadsheet. 该参数仅可用于导入。This argument applies only to importing. 若要导入整个电子表格,请将该参数保留为空。Leave this argument blank to import the entire spreadsheet. 导出到电子表格时,必须将该参数保留为空。When you export to a spreadsheet, you must leave this argument blank. 如果输入范围,则导出将失败。If you enter a range, the export will fail.
UseOAUseOA 可选Optional VariantVariant 不支持该参数。This argument is not supported.

注解Remarks

可以使用 TransferSpreadsheet 方法,在当前 Access 数据库或 Access 项目 (.adp) 和电子表格文件之间导入或导出数据。You can use the TransferSpreadsheet method to import or export data between the current Access database or Access project (.adp) and a spreadsheet file. 还可以将 Excel 电子表格中的数据链接到当前 Access 数据库。You can also link the data in an Excel spreadsheet to the current Access database. 使用链接的电子表格,可以使用 Access 查看和编辑电子表格数据,同时仍支持对 Excel 电子表格程序数据的完全访问权限。With a linked spreadsheet, you can view and edit the spreadsheet data with Access while still allowing complete access to the data from your Excel spreadsheet program. 还可以链接到 Lotus 1-2-3 电子表格文件中的数据,但此类数据在 Access 中为只读。You can also link to data in a Lotus 1-2-3 spreadsheet file, but this data is read-only in Access.

备注

还可以使用 Recordset 对象的 ActiveConnection 属性,利用 ActiveX 数据对象 (ADO) 创建链接。You can also use ActiveX Data Objects (ADO) to create a link by using the ActiveConnection property for the Recordset object.

示例Example

下面的示例在 Lotus 电子表格 Newemps.wk3 的指定范围内将表导入到 Access 的“Employees”表。The following example imports the data from the specified range of the Lotus spreadsheet Newemps.wk3 into the Access Employees table. 它使用电子表格中的第一行作为字段名。It uses the first row of the spreadsheet as field names.

DoCmd.TransferSpreadsheet acImport, 3, _ 
 "Employees","C:\Lotus\Newemps.wk3", True, "A1:G12"

支持和反馈Support and feedback

有关于 Office VBA 或本文档的疑问或反馈?Have questions or feedback about Office VBA or this documentation? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.