[英]Tranfer excel sheet data to access table from excel vba giving error
我正在嘗試將Excel工作表數據轉移到訪問表。 下面的代碼拋出未定義的錯誤變量,並指向acImport 。 從Excel可以使用TransferSpreadsheet方法嗎? 可以使用任何其他方法來轉移工作表數據以僅從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
通過聲明這樣的變量來計算
Const acImport = 0
Const acSpreadsheetTypeExcel9 = 8
appAccess.DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, _
"wemonoff1", ename, True, "WEM-ONOFF!D:E"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.