Error on Dim WApp and Dim WDoc

craigachan

Registered User.
Local time
Today, 04:47
Joined
Nov 9, 2007
Messages
285
Could someone help me with this code. It was working at some point but stopped working. I'm trying to open up a word document '.docx' in read only. It hangs up at the following lines:

Dim WApp as New Word.Application
Dim WDoc as Word.Document

I get: 'User-defined type not defined'

This one is over my head.

Code:
Public Sub DocReadOnly(strDocName)
'strDocName     - Full path and name of document
On Error GoTo DROErr
'------------------- This section for .pdf Files
        Dim FN As String
        Dim PTFile As String
        FN = Forms!ChartMain!ChartMainSub.Form!nDoc
        PTFile = DLookup("PDocs", "CHANLinkPaths") & Trim(Forms!ChartMain!nPID) & "\"
        If Right(strDocName, 4) = ".pdf" Then
 
            Call Launch(FN, PTFile)
            Exit Sub
 
        End If
'-----------------------This section for word docs.
Dim WApp As New Word.Application
Dim WDoc As Word.Document
Dim tempLP As String
tempLP = DLookup("tempDocs", "CHANLinkPaths") & "tempDoc.docx"
MsgBox "You are opening a document as READ ONLY." & vbCrLf & _
        "Any changes will not be saved."
WApp.Documents.Open strDocName, , True
WApp.Visible = True
WApp.ActiveDocument.SaveAs tempLP
 
Set WApp = Nothing
Set WDoc = Nothing
DROExit:
    Exit Sub
DROErr:
    MsgBox "Check Link Path to tempDoc"
    WApp.Documents.Close
    WApp.ActiveDocument.Close
 
    Set WApp = Nothing
    Set WDoc = Nothing
    Resume Next
 
End Sub

Thanks for your help.
 
Have you set a VBA reference to the Word Library?

* start the Visual Basic Editor (press ALT+F11)
* on the Tools menu, click References.
 
That was it! I had exported all of the objects to a new database, and forgot to reset the references. Thanks for your help.
 

Users who are viewing this thread

Back
Top Bottom