[AccessD] Problem with Word Automation

Susan Harkins ssharkins at setel.com
Wed May 9 17:27:35 CDT 2007


Found my error... 

Set doc = appWord.Documents("CustomerSlip.doc")
Set doc = appWord.Documents.Open("C:\WordForms\CustomerSlip.doc", , True)

I thought it was an either/or, but apparently it isn't -- you have to set
the document name AND include the document's name in the Open method. 

Susan H. 

Susan,

    Sample subroutine as given below, on being tested at my end, is found to
work smoothly.

Best wishes,
A.D.Tejpal
---------------

Sample subroutine
===============================
Sub P_GetWordDoc()
    On Error GoTo ErrTrap
    Dim appWord As Word.Application
    Dim doc As Word.Document
    Dim DocPath1 As String, DocPath2 As String
    
    DocPath1 = "C:\TEMP\Test 01.doc"
    DocPath2 = "C:\TEMP\Test 02.doc"
    
    On Error Resume Next
    Err.Clear
    Set appWord = GetObject(, "Word.Application")
    If Err.Number <> 0 Then
        Set appWord = New Word.Application
    End If
    On Error GoTo ErrTrap
  
    Set doc = appWord.Documents.Open(DocPath1, , True)
    
    On Error Resume Next
    Kill DocPath2
    doc.SaveAs DocPath2

ExitPoint:
    On Error Resume Next
    doc.Close
    appWord.Quit
  
    Set doc = Nothing
    Set appWord = Nothing
    On Error GoTo 0
    Exit Sub
        
ErrTrap:
    MsgBox Err.Number & " - " & _
            Err.Description, vbCritical + vbOKOnly, _
            "Error Encountered"
    Resume ExitPoint
End Sub




More information about the AccessD mailing list