Opening Word Document using VBA in Access 2013

自闭症网瘾萝莉.ら 提交于 2019-12-24 18:08:03

问题


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:

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"


回答1:


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

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.



回答2:


Wouldn't be easier just to do:

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

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



来源:https://stackoverflow.com/questions/17973041/opening-word-document-using-vba-in-access-2013

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!