Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Word OLE Automation/VBA Problem
Message
De
17/06/1998 12:09:12
Greg Evans
Ag Communication Systems
Phoenix, Arizona, États-Unis
 
 
À
Tous
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Titre:
Word OLE Automation/VBA Problem
Divers
Thread ID:
00109117
Message ID:
00109117
Vues:
67
I am working with VFP 5.0a and MS Word97

I am attempting to extract a Word document that I have saved in a General field out to a file on disk so that I can either preview or print the document via Word. Everything works great as long as I do not have an already active session of Word going. My problem is that if there is another session of Word active (outside of my VFP App), the creation of the OLE-bound control (.AddObject("olbWord",...) seems to create a phantom instance of a document in the Word session called "Document in Unnamed". In my test program (shown below) the Close() command gets rid of this phantom doc just fine. However, when I paste this same code into my application and run it, I crash on the Close() method. Does anybody have a better way of extracting a Word document from a General field? A way that will not interfere with other sessions of Word that the user may have active?

*// TEST.PRG
*// This test program assumes that the table STATIC is open.
*// The General field containing the Word doc is called DOC.

*// Create a temporary form
oForm=CreateObject("Form")

*// Create OLE Bound Control and Set Properties
WITH oForm
.AddObject("olbWord","Oleboundcontrol")
.olbWord.Top = 0
.olbWord.Left = 0
.olbWord.Height = 1100
.olbWord.Width = 775
.olbWord.ControlSource="Static.doc"
ENDWITH

*// Create a disk file of the document.
tcWordFile="C:\test.doc"
oForm.olbWord.Object.SaveAs(tcWordFile)

*// Check the number of documents open to see if user already has
*// another document open in Word.
lnActiveDocs = oForm.olbWord.Object.Application.Documents.Count()

IF lnActiveDocs > 1
*// Close "Document in Unnamed" created by bound control
lnActiveDocs = oForm.olbWord.Object.Application.Documents("Document in Unnamed").Close()
ELSE
*// Shut down Word session.
oForm.olbWord.Object.Application.Quit()
ENDIF
oForm.RemoveObject("olbWord")
oForm.Release
Release oForm
AG Communication Systems
Greg Evans
Répondre
Fil
Voir

Click here to load this message in the networking platform