简体   繁体   English

从Excel VBA运行访问模块

[英]Run access module from Excel VBA

I am tryng to run this module on Access: 我正在尝试在Access上运行此模块:

Public Sub Retriever_P(path)

DoCmd.TransferSpreadsheet acImport, 10, "Product_Details", path, True, ""

End Sub

From this VBA code in Excel 从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

But I get this Error 2517, "Microsoft Access cannot find the procedure "Retriever_P" 但我收到此错误2517,“ Microsoft Access无法找到过程“ Retriever_P”

The Excel code is part of a bigger macro that creates a DB and then sends it to access. Excel代码是一个较大的宏的一部分,该宏创建一个DB,然后将其发送给Access。 Any Ideas? 有任何想法吗?

Thank you in advance! 先感谢您!

I have found the solution: the problem was that the sub name was the same as the module name. 我找到了解决方案:问题是子名称与模块名称相同。 I didn't know it had to be different, but I hope someone will find this useful! 我不知道它必须有所不同,但我希望有人会发现它有用! Thanks for all the answers guys! 谢谢大家的回答!

I came across another issue while running a simple test attempting to run an Access VBA function in an empty database (except for the VBA code) from an Excel procedure. 我在运行一个简单的测试试图通过Excel过程在空数据库(VBA代码除外)中运行Access VBA函数时遇到另一个问题。 Without any other objects (tables/forms/etc), the Access VBA function was unable to be found. 没有任何其他对象(表/窗体/等),则无法找到Access VBA功能。 Once I put in a nominal table, the call to the Access VBA function from Excel VBA was successful. 放入名义表后,从Excel VBA调用Access VBA函数成功。 Not a usual situation to have an empty database but as I said I was just running a trial to see if the method worked. 拥有空数据库的情况并不常见,但正如我所说,我只是在进行一次试验以查看该方法是否有效。

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

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