clear lcGetFile = Getfile('DOC') oWordEvents=Newobject("WordEvents") Local owrd As 'word.application' owrd = Newobject('word.application') Eventhandler(owrd,oWordEvents) owrd.Documents.Open(m.lcGetFile) owrd.Visible = .T. owrd.Activate Define Class WordEvents As Session OlePublic IMPLEMENTS ApplicationEvents2 IN "C:\PROGRAM FILES\MICROSOFT OFFICE\OFFICE11\MSWORD.OLB" MyDocName = "c:\temp\VFPWasHere.doc" Host = null PROCEDURE init(oHost) this.host = oHost ENDPROC Procedure ApplicationEvents2_Quit() As VOID * Should we even save it to a cursor and erase local file? * in case a save is attempted in between IF FILE(this.myDocName) Create Cursor myCursor (doc m nocptrans,dt t) Insert into myCursor (doc,dt) values (FileToStr(this.myDocName),Datetime()) *Erase (this.myDocName) endif ? 'Quitting word...',Datetime() IF TYPE('this.Host')='O' AND !ISNULL(this.host) Eventhandler(this.Host,this,.t.) this.Host = .null. endif Endproc Procedure ApplicationEvents2_DocumentChange() As VOID ? 'Document change detected...',Datetime() Endproc Procedure ApplicationEvents2_DocumentOpen(Doc As VARIANT) As VOID ? 'Document opened...'+Doc.FullName,Datetime() Endproc Procedure ApplicationEvents2_DocumentBeforeClose(Doc As VARIANT, Cancel As LOGICAL) As VOID ? 'Document closing...'+Doc.Fullname,Datetime() *!* * If current file name is different then ours *!* * save it to where we want it *!* * else do not even save *!* If !( Upper(Trim(Doc.Fullname)) == Upper(Trim(this.myDocName)) ) *!* Doc.Saveas(this.myDocName) *!* Doc.Saved = .t. *!* endif Endproc Procedure ApplicationEvents2_DocumentBeforePrint(Doc As VARIANT, Cancel As LOGICAL) As VOID ? 'Document is about to print...',Datetime() * Cancel the printing so user calls IT staff:) Cancel = .t. Endproc Procedure ApplicationEvents2_DocumentBeforeSave(Doc As VARIANT, SaveAsUI As LOGICAL, Cancel As LOGICAL) As VOID LOCAL lcUserDocName lcUserDocName = Doc.FullName Cancel = .T. ? 'Attempted save..Cancelled save...',Datetime() Local loBalloon,lVisible loBalloon = Doc.Application.Assistant.NewBalloon lVisible = Doc.Application.Assistant.Visible Doc.Application.Assistant.Visible = .T. With loBalloon .Heading = "Sorry. VFP doesn't let you to save '" + m.lcUserDocName + "'" .Show() ENDWITH Doc.Application.Assistant.Visible = m.lVisible Endproc Procedure ApplicationEvents2_NewDocument(Doc As VARIANT) As VOID ? "User created a new document..."+Doc.FullName,DATETIME() Endproc Procedure ApplicationEvents2_WindowActivate(Doc As VARIANT, Wn As VARIANT) As VOID Endproc Procedure ApplicationEvents2_WindowDeactivate(Doc As VARIANT, Wn As VARIANT) As VOID Endproc Procedure ApplicationEvents2_WindowSelectionChange(Sel As VARIANT) As VOID IF sel.start < sel.end ? Datetime(),'User selected text:',sel.text * Change selected text if it contains " fox " - regexp for more fuzzy search/replace * If within a table cell would cause some nasty result-but this is just a sample sel.text = STRTRAN(sel.text," fox "," Visual FoxPro ",1,-1,1) endif Endproc Procedure ApplicationEvents2_WindowBeforeRightClick(Sel As VARIANT, Cancel As LOGICAL) As VOID Endproc Procedure ApplicationEvents2_WindowBeforeDoubleClick(Sel As VARIANT, Cancel As LOGICAL) As VOID Endproc EnddefineCetin