在 Access 2013 中使用 VBA 打开 Word 文档

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17973041/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 16:17:56  来源:igfitidea点击:

Opening Word Document using VBA in Access 2013

vbams-accessms-wordaccess-vba

提问by user2521720

I'm using Access 2013 and created a help button on a form that I would like to open up a Word doc with instructions. Here's the code I tried:

我正在使用 Access 2013 并在我想打开带有说明的 Word 文档的表单上创建了一个帮助按钮。这是我试过的代码:

Private Sub cmdHelp_Click()
    Dim wrdApp As Word.Application
    Dim wrdDoc As Word.Document
    Dim filepath As String

    Set wrdApp = CreateObject("Word.Application")
    wrdApp.Visible = True

    filepath = "C:\...\Handout.docx"
    Set wrdDoc = wrdApp.Documents.Open(filepath)
End Sub

The problem is, when I try to compile I get an error on the first line that says "User-defined type not defined"

问题是,当我尝试编译时,第一行出现错误,提示“未定义用户定义的类型”

回答by Fabio Pereira

Wouldn't be easier just to do:

这样做不会更容易:

Shell "winword ""c:\...\Handout.docx"""

... instead of creating an object just to open the application?

... 而不是创建一个对象只是为了打开应用程序?

回答by Kazimierz Jawor

Please check if you set appropriate reference to Word Library in VBA Environment.

请检查您是否在 VBA 环境中设置了对 Word 库的适当引用。

To do so follow the path:

为此,请遵循以下路径:

Go to VBA Editor >> Menu >> Tools >> References >> 
    Find on the list Microsoft Word XX.X Object Library where 
    XX.X is the highest available number >> 
Check it >> press OK.