如何在Word宏中从VBA打开访问数据库

时间:2019-02-14 22:04:30

标签: vba ms-access ms-word access-vba word-vba

所有内容均在标题中说明。

我需要能够以文字方式运行一个宏,以打开访问数据库。

1 个答案:

答案 0 :(得分:1)

如果要打开和操作Access对象,请考虑:

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

如果您只想打开一个Access文件,然后让用户像往常一样互动,以下对我有用:

'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