I want to use the same technique for word and I have copied the code of bellow in thisdocument of normal project .but it does not work .
Word is a little bit trickier as Excel, the problem is that Word.Ontime can't execute a sub within the codemodule ThisDocument.
Actually, we should place the code into a normal module, but the event variable did not work in such a module. So we have to split the code in both.
Place this code into the code module "ThisDocument" in your Normal.dot:
--- schnipp ---
Option Explicit
Public WithEvents App As Application
Private Sub App_DocumentBeforeSave(ByVal Doc As Document, _
SaveAsUI As Boolean, Cancel As Boolean)
Set Module1.LastDC = Doc
Application.OnTime Now, "Normal.Module1.App_DocumentAfterSave"
End Sub
--- schnapp ---
Create a normal module, name it "Module1" and place this code into it:
--- schnipp ---
Option Explicit
'Is set from App_DocumentBeforeSave
Public LastDC As Document
Public Sub AutoExec()
'Runs automatically when Word opens
Set ThisDocument.App = Application
End Sub
Public Sub App_DocumentAfterSave()
'Called from Ontime
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
fso.CopyFile LastDC.FullName, "C:\backup\word"
End Sub
--- schnapp ---
Save your Normal.dot, close and reopen Word.
Andreas.