Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Word Application open in user's PC, how to...
Message
De
12/09/2006 22:46:44
 
 
À
12/09/2006 17:12:39
Information générale
Forum:
Visual FoxPro
Catégorie:
COM/DCOM et OLE Automation
Divers
Thread ID:
01152901
Message ID:
01153190
Vues:
20
>>>>Can we see part of the code? When I open a second instance of word using createobject(), open a file (Documents.Open(), save it (ActiveDocument.SaveAs(), close it (ActiveDocument.Close(0), and then oWord.quit(), everything about my instance is gone. The other instance doesn't know anything has happened.
>>>>
>>>
>>>The goal here is to create a .DOC from a .TXT output and retain the .TXT on the server to be archived (we don't want to literally convert the file).
>>>
>>>
* Convert .TXT to .DOC format
>>>FUNCTION ConvertDoc
>>>LPARAMETERS lcTxtFile
>>>
>>>#include "wdconst.h"
>>>#DEFINE wdAutoInchesToPoints 72
>>>
>>>LOCAL oWord as "word.application"
>>>oWord = CREATEOBJECT('Word.Application')
>>>
>>>lcFileDoc = LEFT(lcTxtFile,ATC('.txt',lcTxtFile)-1)+'.doc'
>>>IF FILE(lcFileDoc)
>>>   ERASE (lcFileDoc)
>>>ENDIF
>>>IF file(lcTxtFile)
>>>   * open text file
>>>   oWord.WordBasic.FileOpen(lcTxtFile)
>>>   oWord.Selection.TypeParagraph
>>>   oWord.ActiveDocument.Select
>>>   WITH oWord.Selection
>>>      .Range.ListFormat.RemoveNumbers
>>>      .Font.Name = "Courier New"
>>>      .Font.Size = 8
>>>   ENDWITH
>>>   WITH oWord.ActiveDocument.PageSetup
>>>      .LineNumbering.Active = .F.
>>>      .Orientation = 1
>>>      .BottomMargin = .3 * wdAutoInchesToPoints
>>>      .TopMargin = .25 * wdAutoInchesToPoints
>>>      .LeftMargin = 1.0 * wdAutoInchesToPoints
>>>      .RightMargin = 1.0 * wdAutoInchesToPoints
>>>   ENDWITH
>>>   * save document into the doc file in the Word format with password
>>>   With oWord.ActiveDocument
>>>        .Protect(wdAllowOnlyReading,.F.,"xyz123xyz")
>>>        .RemovePersonalInformation = .F.
>>>        .RemoveDateAndTime = .F.
>>>        .SaveAs(lcFileDoc,0)
>>>   EndWith
>>>   oWord.WordBasic.FileClose()
>>>ENDIF
>>>oWord.Quit
>>>RETURN
>>>I've experienced "This file is in use by another application or user. (C:\Documents and Settings\...\normal.dot)" Then it doesn't properly close the application.
>>
>>Does it make a difference if at the end, you use "oWord.ActiveDocument.Close(0)" rather than using wordbasic syntax?
>
>Thanks for your reply. Unfortunately, no. The program goes into loop for each employee, creating .TXT output and then creating .DOC.

I just tried creating a loop that calls your code 10 times, and it runs flawlessly. I'm on WinXp with Word 2003 and VFP9.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform