How to Create object of MS Access Runtime in Excel VBA

后端 未结 1 547
不思量自难忘°
不思量自难忘° 2021-01-23 19:41

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

Set objAccess = CreateObject(\"Access.Application\")


        
相关标签:
1条回答
  • 2021-01-23 19:52

    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".)

    0 讨论(0)
提交回复
热议问题