Results 1 to 2 of 2

Thread: Word save event

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 2003
    Posts
    25

    Word save event

    For security would like to control the folders where Word files are saved ( word app started from a VB app)

    The event I get and the supporting code:

    VB Code:
    1. Option Explicit
    2. Dim WithEvents wrdAppO As Word.Application
    3. Dim WithEvents wrdDocO As Word.Document
    4.  
    5. Private Sub Document_Open()
    6.  
    7. End Sub
    8.  
    9. Private Sub wrdAppO_Close()
    10.  
    11. End Sub
    12.  
    13. Private Sub wrdDocO_Close()
    14. ' on close path
    15. Debug.Print "5] on close path " & wrdDocO.Path
    16. End Sub
    17.  
    18. ' no event like this
    19. Private Sub wrdDocO_DocumentBeforeSaveAs(ByVal Doc As Document, SaveAsUI As Boolean, Cancel As Boolean)
    20. Debug.Print "1]doc save as to " & Doc.Path, Doc.Name
    21. If LCase(Doc.Path) <> "c:\tmp" Then
    22.     MsgBox "bad path cant save in : " & Doc.Path
    23. End If
    24. End Sub
    25.  
    26. ' no event like this
    27. Private Sub wrdAppO_DocumentBeforeSaveAs(ByVal Doc As Document, SaveAsUI As Boolean, Cancel As Boolean)
    28. Debug.Print "2]app sav as  to " & Doc.Path, Doc.Name
    29. If LCase(Doc.Path) <> "c:\tmp" Then
    30.     MsgBox "bad path cant save in : " & Doc.Path
    31. End If
    32. End Sub
    33.  
    34. Private Sub wrdAppO_DocumentBeforeSave(ByVal Doc As Document, SaveAsUI As Boolean, Cancel As Boolean)
    35. Debug.Print "3] app save to " & Doc.Path, Doc.Name
    36. If LCase(Doc.Path) <> "c:\tmp" Then
    37.     MsgBox "bad path cant save in : " & Doc.Path
    38. End If
    39. End Sub
    40.  
    41. Private Sub wrdDocO_DocumentBeforeSave(ByVal Doc As Document, SaveAsUI As Boolean, Cancel As Boolean)
    42. Debug.Print "4] doc save to " & Doc.Path, Doc.Name
    43. End Sub
    44.  
    45. Private Sub Form_Load()
    46. Dim pwdS As String
    47. Dim quitB As Boolean
    48. On Local Error GoTo errH
    49. Set wrdAppO = New Word.Application
    50. 'wrdAppO.OleRequestPendingTimeout = 999999
    51. wrdAppO.Visible = True
    52. Set wrdDocO = wrdAppO.Documents.Open("c:\tmp\33a.doc")   ' .Add(, , , True)
    53. 'wrdDocO.OleRequestPendingTimeout = 999999
    54. wrdDocO.Variables("tushar1") = "as8"
    55. Call wrdDocO.SaveAs("c:\tmp\33a.doc", , , pwdS, False, , , , , , vbNull)
    56.  
    57. Err.Clear
    58. If Err.Number <> 0 Then
    59. errH:
    60.     Debug.Print "ERR " & Err.Number & " " & Err.Description
    61. End If
    62. 'finalize
    63. On Local Error Resume Next
    64. If quitB Then
    65.     quitApp
    66. End If
    67. End Sub
    68.  
    69. ' to close word app and clean up, since it is visible user can quit too
    70. ' can we get the quit event ? - close?
    71. Sub quitApp()
    72. On Local Error Resume Next
    73. wrdAppO.Quit
    74. Set wrdAppO = Nothing
    75. Set wrdDocO = Nothing
    76. End Sub

    I tried the event:

    VB Code:
    1. Private Sub wrdAppO_DocumentBeforeSaveAs(ByVal Doc As Document, SaveAsUI As Boolean, Cancel As Boolean)
    2. Debug.Print Doc.Path, Doc.Name
    3. ' but this is not a valid event - is never triggered by the word app ((
    4. End Sub


    any ideas ?
    Last edited by tgkprog; Nov 27th, 2003 at 02:39 AM.
    - tushar

  2. #2
    Fanatic Member WorkHorse's Avatar
    Join Date
    Jul 2002
    Location
    Where you live.
    Posts
    591
    wrdAppO_DocumentBeforeSave should always fire whether the user selects Save or SaveAs.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width