Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Allow user to modify a Word document?
Message
From
13/01/2009 13:39:48
 
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01372571
Message ID:
01373302
Views:
78
Obviously I'm missing or misunderstanding some key point but I'll keep working with it. . Thanks.

First you create a handler class that looks like this (note that the path to your type library is probably different than mine. Do not worry about the hard-coded path - this is a design time issue, not a runtime issue. So if your end-users are running and EXE, it is not an issue:
DEFINE CLASS WordHandler AS session OLEPUBLIC

  IMPLEMENTS ApplicationEvents2 IN "d:\office2003\office11\msword.olb"

  PROCEDURE ApplicationEvents2_Quit() AS VOID
  * add user code here
  ENDPROC

  PROCEDURE ApplicationEvents2_DocumentChange() AS VOID
  * add user code here
  ENDPROC

  PROCEDURE ApplicationEvents2_DocumentOpen(Doc AS VARIANT) AS VOID
  * add user code here
  ENDPROC

  PROCEDURE ApplicationEvents2_DocumentBeforeClose(Doc AS VARIANT, Cancel AS LOGICAL) AS VOID
    * add user code here to do whatever needs to be done after the user
    * edits the document
  ENDPROC

  PROCEDURE ApplicationEvents2_DocumentBeforePrint(Doc AS VARIANT, Cancel AS LOGICAL) AS VOID
  * add user code here
  ENDPROC

  PROCEDURE ApplicationEvents2_DocumentBeforeSave(Doc AS VARIANT, SaveAsUI AS LOGICAL, Cancel AS LOGICAL) AS VOID
  * add user code here
  ENDPROC

  PROCEDURE ApplicationEvents2_NewDocument(Doc AS VARIANT) AS VOID
  * add user code here
  ENDPROC

  PROCEDURE ApplicationEvents2_WindowActivate(Doc AS VARIANT, Wn AS VARIANT) AS VOID
  * add user code here
  ENDPROC

  PROCEDURE ApplicationEvents2_WindowDeactivate(Doc AS VARIANT, Wn AS VARIANT) AS VOID
  * add user code here
  ENDPROC

  PROCEDURE ApplicationEvents2_WindowSelectionChange(Sel AS VARIANT) AS VOID
  * add user code here
  ENDPROC

  PROCEDURE ApplicationEvents2_WindowBeforeRightClick(Sel AS VARIANT, Cancel AS LOGICAL) AS VOID
  * add user code here
  ENDPROC

  PROCEDURE ApplicationEvents2_WindowBeforeDoubleClick(Sel AS VARIANT, Cancel AS LOGICAL) AS VOID
  * add user code here
  ENDPROC

ENDDEFINE
And you use it in your code like this:
oWord = CREATEOBJECT ('Word.Application')
oHandler = NEWOBJECT( 'WordHandler', 'WordJandler.prg')
EVENTHANDLER( oWord, oHandler )
*** Do whatever here
*** Open document, etc
oWord.Visible = .T.
Now, whenever the user tries to close the document, any code that you have written in the ApplicationEvents2_DocumentBeforeClose will execute, allowing you to save changes, create PDF, etc, before closing the document.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform