I want to write a program in word that when I save a document ,save a copy to another location.
I open word document and press alt+f11 and then in normal project I insert class module called "ThisApplication.
According to the instructions of word.mvps.org/faqs/macrosvba/appclassevents.htm have defined a class madule in normal project and insert some codes:
Option Explicit
Public WithEvents oApp As Word.Application
Private Sub oApp_DocumentBeforeSave(ByVal Doc As Document, SaveAsUI As Boolean, Cancel As Boolean)
SaveToTwoLocations
End Sub
Sub SaveToTwoLocations()
Dim strFileA, strFileB
strFileA = ActiveDocument.Name
'Define backup path shown in blue below
strFileB = "C:\backup\" & strFileA
ActiveDocument.SaveAs FileName:=strFileB
End Sub
and then insert a new module and insert the bellow codes:
Option Explicit
Dim oAppClass As New ThisApplication
Public Sub AutoExec()
Set oAppClass.oApp = Word.Application
End Sub
but when i run the macro , appears Compile error:expected user defined type not project
error in line of
Dim oAppClass As New ThisApplication
would you please tell me where is the problem and how can I solve the problem? Thanks
I open word document and press alt+f11 and then in normal project I insert class module called "ThisApplication.
According to the instructions of word.mvps.org/faqs/macrosvba/appclassevents.htm have defined a class madule in normal project and insert some codes:
Option Explicit
Public WithEvents oApp As Word.Application
Private Sub oApp_DocumentBeforeSave(ByVal Doc As Document, SaveAsUI As Boolean, Cancel As Boolean)
SaveToTwoLocations
End Sub
Sub SaveToTwoLocations()
Dim strFileA, strFileB
strFileA = ActiveDocument.Name
'Define backup path shown in blue below
strFileB = "C:\backup\" & strFileA
ActiveDocument.SaveAs FileName:=strFileB
End Sub
and then insert a new module and insert the bellow codes:
Option Explicit
Dim oAppClass As New ThisApplication
Public Sub AutoExec()
Set oAppClass.oApp = Word.Application
End Sub
but when i run the macro , appears Compile error:expected user defined type not project
error in line of
Dim oAppClass As New ThisApplication
would you please tell me where is the problem and how can I solve the problem? Thanks