How to Create object of MS Access Runtime in Excel

2020-04-20 21:56发布

I have Microsoft Access Runtime not full version of Microsoft Access, When i create object in Excel VBA

Set objAccess = CreateObject("Access.Application")

That time i am getting

Error 429 "ActiveX component can't create object."

Suggest how to create object?

1条回答
欢心
2楼-- · 2020-04-20 22:10

I'm not sure whether this information is still relevant to OP, but it might help out others (like me) who were looking for a solution:

In cases where the simple route

Dim AccApp as Object
Set AccApp = CreateObject("Access.Application")

doesn't work (e.g. because only the Runtime Version of Access is available), the following route seems to work:

Const PathToDBFile as String = "W:\here\Your\DB\lies.accdb"
Const PathToAccess as String = "C:\Program files\YourOfficeVersion\MSACCESS.EXE"
Dim ShellCmd as String
' Piece together the parts (yes, the quotes are necessary in case there are spaces in the paths) 
ShellCmd = """" & PathToAccess & """ """ & PathToDBFile & """"
' Execute the command in the shell
VBA.Shell ShellCmd
' Now GetObject can return the newly created instance of Access
Dim AccApp as Object
Set objAcc = GetObject(PathToDBFile)

(Source)

This code is only the bare bones to show the essential steps. One likely wants to make sure there isn't already an instance of Access running. Also I've not yet worked out how I can reliably get the path to the MSAccess.exe on different systems. But the above worked for me when I tried on a system with only the Runtime Version installed. (I was able to get the correct return from AccApp.Run "MyFunction".)

查看更多
登录 后发表回答