Yep :)
Using Word automation you can access the opened documents and do what you will with them. There are plenty resources out there
(just search MSDN or groups.google.com) about automating Office applications.
You need to reference an Interop wrapped Word assembly. You can do this by opening the project references dialog in VS.NET, hitting
the COM tab and browsing for Microsoft Word. I don't believe Office supplies any Primary Interop assembly for Word at this time,
but if I'm wrong it would be under the .NET tab, or in a folder somewhere in the office heirarchy of folders. For now, just use COM
tab and select Word as I suggested. If it's not in the list, simply browse to the executable and add it. VS.NET will use a tool to
wrap the assembly for you.
Here are examples of using automation in C#:
using Word;
...
Word.Application app =
Activator.CreateInstance(Type.GetTypeFromProgID("W ord.Application", false)) as Word.Application;
This code places the instance of Word in the ROT (running object table). Now, when you close your app, Word is closed too.
Here's another way of accessing Word (this way won't link Word to your process):
Word.Application app =
System.Runtime.InteropServices.Marshal.GetActiveOb ject("Word.Application") as Word.Application;
This code retrieves an instance of Word from the ROT, but does not "link" it to the running process. When your app is closed, Word
is not.
If "app" = null then run the following line, and then run the above line once more (again testing for null!):
System.Diagnostics.Process.Start("Word");
GL
--
Dave Sexton
dave@www..jwaonline..com
-----------------------------------------------------------------------
<gi***@consultant.com> wrote in message news:de**************************@posting.google.c om...
Thanks for your response Dave. I tested it using a text document
opening it in notepad and it works as I would have hoped, so you
appear to be correct in that it is opening Word in the same process.
That explains the problem a little further, however my problem still
remains...I need to be able to kill off one of the word documents
without killing off the other. Any ideas?
Thanks
Gavin
"Dave" <NO*********@dotcomdatasolutions.com> wrote in message news:<OE**************@TK2MSFTNGP12.phx.gbl>... Is Word opening b.doc using the same process as the first? That would explain it.
--
Dave Sexton
dave@www..jwaonline..com
-----------------------------------------------------------------------
<gi***@consultant.com> wrote in message news:de**************************@posting.google.c om... >I have a requirement to initiate more than one instance of an
> application using the filenames. (the example below will start two
> instances of MS Word).
>
> My problem is that I need to kill each instance individually, but this
> does not appear possible using the Process object. When I run the
> example below the process object "p" can be viewed using Quick Watch
> however process object p2 is displayed as undefined, with the added
> affect of not being able to kill instance p2.
>
> -Code----------------------------------------------
> ProcessStartInfo startInfo = new ProcessStartInfo("a.doc");
> startInfo.WindowStyle = ProcessWindowStyle.Minimized;
> Process p = Process.Start(startInfo);
> .....
> ProcessStartInfo startInfo2 = new ProcessStartInfo("b.doc");
> startInfo2.WindowStyle = ProcessWindowStyle.Minimized;
> Process p2 = Process.Start(startInfo2);
> ...
> p.Kill();
> ...
> p2.Kill();
> -End Code----------------------------------------------
>
>
> Does anyone have an explanation for this?
> Is there another way of doing it?
>
> Regards
> Gavin