简体   繁体   中英

How to open an access database from the VBA in a Word Macro

All is explained in the title.

I need to be able to run a macro in word that opens up an access database.

If you want to open and manipulate Access object, consider:

Public Sub OpenDB()
Dim db As Access.Application
Set db = New Access.Application
db.OpenCurrentDatabase "C:\My Documents\db2.mdb"
db.Application.Visible = True 'optional
'code to manipulate Access
End Sub

If you just want to open an Access file and then let user interact as normal, following works for me:

'Shell function requires literal quote marks in the target filename string argument, apostrophe delimiters fail, hence the quadrupled quote marks
Shell SysCmd(acSysCmdAccessDir) & "MSAccess.exe " & """" & "C:\My Documents\dbname.accdb" & """", vbNormalFocus

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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