【发布时间】:2015-04-17 09:56:08
【问题描述】:
我正在尝试在 Access 上运行此模块:
Public Sub Retriever_P(path)
DoCmd.TransferSpreadsheet acImport, 10, "Product_Details", path, True, ""
End Sub
来自 Excel 中的此 VBA 代码
Private Sub CommandButton210_Click()
Dim appAccess As Access.Application
Set appAccess = New Access.Application
Dim Target As String: Target = ThisWorkbook.Sheets("CODE").Cells(8, 4).Value
Dim path As String: path = ThisWorkbook.Sheets("CODE").Cells(5, 13).Value
appAccess.OpenCurrentDatabase Target
appAccess.Visible = True
appAccess.DoCmd.SetWarnings False
appAccess.UserControl = True
appAccess.DoCmd.OpenQuery "Clean Product_Details"
appAccess.Run "Retriever_P", path
appAccess.CloseCurrentDatabase
End Sub
但我收到此错误 2517,“Microsoft Access 找不到过程“Retriever_P”
Excel 代码是一个更大的宏的一部分,该宏创建一个数据库,然后将其发送给访问。 有什么想法吗?
提前谢谢你!
【问题讨论】:
-
我认为,Run 方法接受一个函数,而不是一个子。因此,尝试将 Retriever_P 更改为函数。然后再试一次。还要确保将函数放置在标准模块中,而不是放在表单后面。
-
我试过了,还是一样的错误!模块是使用 Access 2013 创建的转换宏。我创建了宏,然后将其转换为 VBA 并进行了编辑,因此将其放在模块下。
-
这不是 sub vs function 的问题。我尝试使用 sub 它可以工作。尝试将 CommandButton210_Click 更改为 Private Sub CommandButton210_Click() Dim appAccess As Access.Application Set appAccess = CreateObject("Access.Application") appAccess.OpenCurrentDatabase ThisWorkbook.Sheets("CODE").Cells(5, 13).Value, False appAccess .Run "Retriever_P", "PATH..." Set appAccess = Nothing End Sub 见以下链接:msdn.microsoft.com/en-us/library/office/ff193559.aspx