applicatio event procedure

Joined
Dec 10, 2011
Messages
1
Reaction score
0
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top