Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Word Application open in user's PC, how to...
Message
From
13/09/2006 12:59:24
 
 
To
13/09/2006 11:18:06
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Miscellaneous
Thread ID:
01152901
Message ID:
01153430
Views:
16
>>>>>>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.
>
>I'm on Win XP with Word 2003 but VFP is version 8. It goes into loop for 650 employees.
>
>UPDATE: Instead of launching Word in the function subroutine, I moved CreateObject to the beginning of the program (that calls the function 650 times) and Quit in the end. It got rid of the error message "the file is in use by another application".

Interesting. I was going to suggest creating the instance prior to the loop and quitting it after the loop is finished, but other than speed, I didn't see why it would make a difference, so I didn't bother. I guess in 650 creatings and closings, maybe the system can get a bit confused.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform