vba 从 Excel 调用 Access Sub
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9472652/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Calling Access Sub from Excel
提问by tttt555
I'm trying to call a subroutine in an Access database from Excel. This sub then call a number of other subroutines, all contained within the database. I saw a number of other posts where this was discouraged, but for reasons, Excel needs to be the front-end for this. I tried:
我正在尝试从 Excel 调用 Access 数据库中的子例程。这个子程序然后调用许多其他子程序,所有这些子程序都包含在数据库中。我看到了一些不鼓励这样做的其他帖子,但出于某些原因,Excel 需要作为前端。我试过:
Sub TestRun()
Dim acObj As Access.Application
Set acObj = CreateObject("Access.Application")
acObj.Application.Visible = True
acObj.OpenCurrentDatabase "C:\testMDB\TEST.mdb", False, "password"
acObj.Application.Run ("TestRunAccess")
End Sub
The database is part of a workgroup with a password - running it this way still prompts for the password. I'm not very familiar with Access - how would I go about doing this? What references would I need to include?
数据库是具有密码的工作组的一部分 - 以这种方式运行它仍然会提示输入密码。我对 Access 不是很熟悉 - 我将如何去做?我需要包括哪些参考资料?
回答by Fionnuala
That would be:
那将是:
''Reference: Microsoft Access x.x Object Library
Dim acObj As New Access.Application
''Set acObj = CreateObject("Access.Application")
acObj.Application.Visible = True
acObj.OpenCurrentDatabase "C:\testMDB\TEST.mdb",,"ADatabasePassword"
acObj.Application.Run "TestRunAccess"
You may prefer to use late binding if you wish to avoid problems with references, in which case:
如果您希望避免引用出现问题,您可能更喜欢使用后期绑定,在这种情况下:
Dim acObj As Object
Set acObj = CreateObject("Access.Application")
acObj.Application.Visible = True
acObj.OpenCurrentDatabase "C:\testMDB\TEST.mdb",,"ADatabasePassword"
acObj.Application.Run "TestRunAccess"