【发布时间】:2014-04-04 17:56:32
【问题描述】:
我正在尝试将 Excel 工作表数据传输到访问表。下面的代码抛出一个错误 variable not defind 并指向 acImport 。 TransferSpreadsheet 方法适用于 excel 吗?任何替代方法都可以传输工作表数据以仅从 excel 访问。
Private Sub Cal_WEM_Click()
Dim appAccess As Object
Dim aPath, aDbase, aDSource, aTable, exePath As String
Dim fileParam As String
aPath = ActiveWorkbook.Path
aDbase = "Linear.accdb"
aDSource = aPath & "\" & aDbase
Set appAccess = CreateObject("Access.Application")
appAccess.Visible = True
appAccess.OpenCurrentDatabase aDSource
appAccess.DoCmd.TransferSpreadsheet transfertype:=acImport, _
tablename:="yorno", _
FileName:=aPath, Hasfieldnames:=True, _
Range:="WEM!D:E", SpreadsheetType:=5
appAccess.DoCmd.OpenForm "Input_Form_WEM"
Application.DisplayAlerts = False
ThisWorkbook.Saved = True
Application.Quit
Exit Sub
End Sub
【问题讨论】:
-
此代码中的 acImport 在哪里?
-
不是预定义的吗。如何在 excel 中指定相同的 Tranferspreadsheet 命令,因为它可以通过使用相同的 Docmd 进行访问