Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

proper way to open multiple word docs

Status
Not open for further replies.

choppysuey

Technical User
Mar 28, 2001
54
US
I'm interested in knowing what the best way is to open multiply word docs in vfp6. If I have 10 docs i.e. 1.doc, 2.doc, 3.doc, etc and want to open all of them I use the following simple loop.

lcSuffix = '.doc'
oWord = CREATEOBJECT('Word.Application')
FOR lnCounter=1 TO 10 STEP 1
oWord.documents.open(str(lnCounter)+lcSuffix)
ENDFOR
oWord.Visible

However doing so opens up 10 winword.exe processes. How do we go about opening a single instance of msword and then opening up the ten docs within that single instance. In addtion, how then do you reference each document?

Thanks in advance.
 
Hello ChoppySuey.

>> I'm interested in knowing what the best way is to open multiply word docs in vfp6. If I have 10 docs i.e. 1.doc, 2.doc, 3.doc, etc and want to open all of them I use the following simple loop. <<

If these documents are existing documents, your code should work just fine. If you are creating new documents, use code like this:

Code:
lcSuffix = '.doc'
oWord = CREATEOBJECT('Word.Application')
FOR lnCounter = 1 TO 10
  oDoc = oWord.documents.add()
  oDoc.SaveAs( str(lnCounter)+lcSuffix )
ENDFOR
oWord.Visible = .T.

>> However doing so opens up 10 winword.exe processes. <<

That is not the case. The CREATEOBJECT() function opens a new instance of Word. But the oWord.Document.Add() ( or .Open() ) does not create a new instance of Word. What makes you think that this is happening?

>> In addtion, how then do you reference each document? <<

You can reference it by its name like so:

Code:
oDoc = oWord.Documents( '1.doc' )
?oDoc.Name

or by its index

Code:
oDoc = oWord.Documents( 1 )
?oDoc.Name


Marcia G. Akins
 
Thanks for the posts Mike and Marcia. The links that Mike provided were very helpful.

Marica, I have VFP6 running on a Win200 machine and after executing the look I was using to open the 10 word docs, I see 10 winword.exe processes running under the processes tab each taking up a chunk of memory. That is why I needed to find out how to open a single winword.exe and then open up documents in that. This is what I ended up with to open my docs.

lprefix = 'c:\testdocs\b'
lcSuffix = '.txt'

loWord = Createobject("word.Application")

FOR lnCounter=1 TO 5 STEP 1
loWord = getOBJECT(,'word.application')
loWord.Documents.Open(lprefix+alltrim(str(lnCounter))+lcSuffix)
ENDFOR
loWord.Visible = .T.
 
Hello ChoppySuey.

>> after executing the code I was using to open the 10 word docs, I see 10 winword.exe processes running under the processes tab each taking up a chunk of memory. <<

In that case, you are not running the same code that you posted. I just ran this code:

Code:
lcSuffix = '.doc'
oWord = CREATEOBJECT('Word.Application')
FOR lnCounter=1 TO 10 STEP 1
  oDoc = oWord.documents.add()
  oDoc.SaveAs( str(lnCounter)+lcSuffix )
ENDFOR
oWord.Visible=.t.

Opened up the task manager, and saw exactly 1 entry for WinWord.exe under the processes tab.

>> loWord = getOBJECT(,'word.application') <<

All this does is return the same reference that you created using CREATEOBJECT(). Since you already have a reference to that instance of Word, this code is not needed.






Marcia G. Akins
 
Marcia

I believe this is related to the version of Word (check the Microsoft link I posted in my post above). The problem seems specific to Word2000.

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Hello Mike.

>> I believe this is related to the version of Word (check the Microsoft link I posted in my post above). The problem seems specific to Word2000. <<

As a matter of fact, I did read the article and, to the best of my knowledge, it is supporting exactly what I said. This is what it says in the article:

In the Single Document Interface, only one instance of the Word program (Winword.exe) is running. To confirm this, do one of the following to display the Windows task list

However, ChoppySuey has said that issuing this command:

Code:
oWord.Documents.Open( '1.doc' )

is launching a new instance of Word. ChoppySuey explicitly said that the processes tab of the task list showed multiple instances of Word running.

The article says that this should not be the case.



Marcia G. Akins
 

Marcia

Funny I read it totally differently.

SYMPTOMS
When you create or open an additional document, another instance of Word appears to run.

NOTE: In earlier versions of Word, when multiple documents are opened, only one Word button appears on the Windows taskbar. However, in Word 2000, when multiple documents are opened, a separate button appears for each on the Windows taskbar.


Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Ran original code posted on Win2000 machine, Word 2002, VFP6

lcSuffix = '.doc'
oWord = CREATEOBJECT('Word.Application')
FOR lnCounter=1 TO 10 STEP 1
oWord.documents.open(str(lnCounter)+lcSuffix)
ENDFOR
oWord.Visible = .T.

When I went into the process tab of taskmanager, I saw 10 winword.exe processes running.

I run the same code on WinXP machine, Word 2002, VFP6 and get what you were saying Marcia; a single winword.exe process running with all 10 documents opened in it. How do you explain that? I will retest code on another Win2000 machine and see. Thanks for your replies.
 
Take a look at my AppLaunch Method that uses the shellexecute API. I posted a message about it at:

Hyperlink to a file
Thread184-243825

This is great for launching most files.



Jim Osieczonek
Delta Business Group, LLC
 
Hi Mike.

>> another instance of Word appears to run. <<

I think that the operative word here is "appears" ;-)

The portion of the article that I quoted says that you should only see a single instance of Word on the processes tab of the task list.

Of course, I could be wrong.

I tested this on my Windows XP machine. I am going to fire up my lap top (which runs Win2K) and test on that machine...



Marcia G. Akins
 
Hello ChoppySuey.

>> Ran original code posted on Win2000 machine, Word 2002, VFP6 <<

I tested this code on:

WinXP - Word XP
Win2K - Word2K

Same results - both machines. On the applications tab of the task manager I saw all 10 documents. But on the processes tab I saw only a single instance of WindWord.exe.




Marcia G. Akins
 

Marcia

Instead of trying to test this under our own condition, I think the poster is concerned about his own findings :
I see 10 winword.exe processes running under the processes tab each taking up a chunk of memory.

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Hello Mike.

>> I think the poster is concerned about his own findings <<

That may be. However, these findings totally contradict what is in MSDN as well as my tests under both Win2K and WinXP.

Personally, if I found such an anomoly on one of my machines, I would want to know what was causing it. Wouldn't you?



Marcia G. Akins
 
Marcia

MarciaAkins said:
Personally, if I found such an anomoly on one of my machines, I would want to know what was causing it. Wouldn't you?

Yes, and perhaps a re-install of Word might be in order.


Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Thanks everyone for your help. After a reinstall of Word everything was as it should be. One process, 10 opened docs.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top