How to steer the Word documents in already opened Word application

G

Guest

Hi,

I have the following question. I’m writing the program in C++, which is
opening in background the Word document, modifying and then closing it. Till
now each document has been opened with separate Word application and after
modification has been closed:
CApplication objWord;
if(!objWord.CreateDispatch("Word.Application"))
......
CDocuments docs(objWord.get_Documents());
doc.AttachDispatch(docs.Open(....));
......
docs.Close(covFalse,covOptional,covOptional);
objWord.Quit(covFalse,covTrue,covFalse);

Now I want to open Word application only once, and then in consecutive order
open, manipulate and close the documents.

Of course I can check whether “winword.exe†process existing or not and also
read the PID, but how can I steer the document?
 
C

Cindy M.

Hi =?Utf-8?B?U3VyZW4=?=,

It's always a good idea to read a few messages before posting to a group. If you
had done so, you'd have noticed that this group is targeted at end-users, not
developers. You're more likely to get a response to your question in a group like
office.developer.automation.

http://msdn.microsoft.com/newsgroups/default.aspx?dg=microsoft.public.office.develo
per.automation&lang=en&cr=US

In the .NET framework I'd use reflection and marshaling with the
GetActiveObject("Word.Appliction") method, then cast this to a Word.Application
object. I don't know what the corresponding C++ syntax is.
I have the following question. I’m writing the program in C++, which is
opening in background the Word document, modifying and then closing it. Till
now each document has been opened with separate Word application and after
modification has been closed:
CApplication objWord;
if(!objWord.CreateDispatch("Word.Application"))
......
CDocuments docs(objWord.get_Documents());
doc.AttachDispatch(docs.Open(....));
......
docs.Close(covFalse,covOptional,covOptional);
objWord.Quit(covFalse,covTrue,covFalse);

Now I want to open Word application only once, and then in consecutive order
open, manipulate and close the documents.

Of course I can check whether “winword.exe†process existing or not and also
read the PID, but how can I steer the document?

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply in
the newsgroup and not by e-mail :)
 
G

Guest

Hi Cindy,

Thank you for notification, I'll move to that group with my question.
I also found that my question was not presented very clear. I'll try to
explain it better.
The problem is following. I have a service task, which is working according
to some algorithm. From time to time it creates the process, runs the MS Word
application, opens the Word document, manipulates it and then closes the
document and Word application.
Now I should increase the speed of this process. I have found that running
the Word application consumed most of the time. Therefore I have decided to
open the Word application only once and then, when it is necessary, open and
manipulate the Word documents.

The only information I have is PID (PROCESS_INFORMATION) of the process,
created by CreateProcess.

My question is following.

How can I get access to the already opened Word application, open there the
Word document and manipulate it.

Thank you in advance,

Suren Karabekyan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top