Option Explicit
Dim WithEvents wrdAppO As Word.Application
Dim WithEvents wrdDocO As Word.Document
Private Sub Document_Open()
End Sub
Private Sub wrdAppO_Close()
End Sub
Private Sub wrdDocO_Close()
' on close path
Debug.Print "5] on close path " & wrdDocO.Path
End Sub
' no event like this
Private Sub wrdDocO_DocumentBeforeSaveAs(ByVal Doc As Document, SaveAsUI As Boolean, Cancel As Boolean)
Debug.Print "1]doc save as to " & Doc.Path, Doc.Name
If LCase(Doc.Path) <> "c:\tmp" Then
MsgBox "bad path cant save in : " & Doc.Path
End If
End Sub
' no event like this
Private Sub wrdAppO_DocumentBeforeSaveAs(ByVal Doc As Document, SaveAsUI As Boolean, Cancel As Boolean)
Debug.Print "2]app sav as to " & Doc.Path, Doc.Name
If LCase(Doc.Path) <> "c:\tmp" Then
MsgBox "bad path cant save in : " & Doc.Path
End If
End Sub
Private Sub wrdAppO_DocumentBeforeSave(ByVal Doc As Document, SaveAsUI As Boolean, Cancel As Boolean)
Debug.Print "3] app save to " & Doc.Path, Doc.Name
If LCase(Doc.Path) <> "c:\tmp" Then
MsgBox "bad path cant save in : " & Doc.Path
End If
End Sub
Private Sub wrdDocO_DocumentBeforeSave(ByVal Doc As Document, SaveAsUI As Boolean, Cancel As Boolean)
Debug.Print "4] doc save to " & Doc.Path, Doc.Name
End Sub
Private Sub Form_Load()
Dim pwdS As String
Dim quitB As Boolean
On Local Error GoTo errH
Set wrdAppO = New Word.Application
'wrdAppO.OleRequestPendingTimeout = 999999
wrdAppO.Visible = True
Set wrdDocO = wrdAppO.Documents.Open("c:\tmp\33a.doc") ' .Add(, , , True)
'wrdDocO.OleRequestPendingTimeout = 999999
wrdDocO.Variables("tushar1") = "as8"
Call wrdDocO.SaveAs("c:\tmp\33a.doc", , , pwdS, False, , , , , , vbNull)
Err.Clear
If Err.Number <> 0 Then
errH:
Debug.Print "ERR " & Err.Number & " " & Err.Description
End If
'finalize
On Local Error Resume Next
If quitB Then
quitApp
End If
End Sub
' to close word app and clean up, since it is visible user can quit too
' can we get the quit event ? - close?
Sub quitApp()
On Local Error Resume Next
wrdAppO.Quit
Set wrdAppO = Nothing
Set wrdDocO = Nothing
End Sub