Visual Basic and Word Events

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Phillip Wu

    #1

    Visual Basic and Word Events

    Hi,

    I am starting the Word application in Visual Basic.
    I want my Visual Basic routine to be called when the user closes the
    document in Word.

    I am expecting that when the user closes test.doc then the routine
    myword_close should be run.

    But it does not work!

    Please tell me how I should proceed.

    Thanks in advance for any help.

    Phillip
    =============== =============== =============== =============== ===========
    Public mydoc As Document
    Public myword As Word.Applicatio n

    Sub start_editor()

    ' Start word
    On Error GoTo wordprob
    Set myword = CreateObject("W ord.Application ")
    If myword Is Nothing Then
    MsgBox "Could not start word"
    Exit Sub
    End If
    On Error GoTo 0

    ' Open the document
    Set mydoc = myword.Document s.Open("c:\TEMP \TEST.DOC")
    myword.Visible = True

    Exit Sub

    wordprob:
    MsgBox "Could not start Word " & Err.Description
    Exit Sub
    End Sub

    '
    ' --- Event handler for Close
    '
    Sub myword_Close()
    MsgBox "Close called"
    End Sub
Working...