Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Allow user to modify a Word document?
Message
De
13/01/2009 13:39:48
 
Information générale
Forum:
Visual FoxPro
Catégorie:
COM/DCOM et OLE Automation
Versions des environnements
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Divers
Thread ID:
01372571
Message ID:
01373302
Vues:
94
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.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform