GetObject of Active Word Document VB 2005??

G

Guest

Hi all, I'm creating a VB 2005 program which deal with MS Word Document. The
program allows users to select/put cursor on any Word doc that shown on the
screen and hit any button on my program to perform some task on the selected
document. There could be a few word docs opened on the screen.

Now, my question is... how do get the object of the user's selected word
doc? I tried the following codes, but it didn't point/refer to the user's
selected word doc.

Dim tWord As Microsoft.Office.Interop.Word.Application
Dim tDoc As Microsoft.Office.Interop.Word.Document

tWord = GetObject(, "Word.Application")

tDoc = tWord.ActiveWindow.Document


Please assume that the Word docs that shown on the screen might NOT be
already saved. So the window title of each Word doc could be "Document 1",
"Document 2" or "Document 3".

Please help if you know the answer. Thanks.
 
T

Tom Shelton

Hi all, I'm creating a VB 2005 program which deal with MS Word Document. The
program allows users to select/put cursor on any Word doc that shown on the
screen and hit any button on my program to perform some task on the selected
document. There could be a few word docs opened on the screen.

Now, my question is... how do get the object of the user's selected word
doc? I tried the following codes, but it didn't point/refer to the user's
selected word doc.

Dim tWord As Microsoft.Office.Interop.Word.Application
Dim tDoc As Microsoft.Office.Interop.Word.Document

tWord = GetObject(, "Word.Application")

tDoc = tWord.ActiveWindow.Document

Please assume that the Word docs that shown on the screen might NOT be
already saved. So the window title of each Word doc could be "Document 1",
"Document 2" or "Document 3".

Please help if you know the answer. Thanks.

Have a look at Marshal.GetActiveObject.
 
G

Guest

Hi Tom, thanks for your suggestion, but it didn't work out. It's stil same,
the GetActiveObject method doesn't get the user's selected document, indeed,
it simply get one of the opened documents on the screen.

Do you have anymore suggestion? Thanks.
 
T

Tom Shelton

Hi Tom, thanks for your suggestion, but it didn't work out. It's stil same,
the GetActiveObject method doesn't get the user's selected document, indeed,
it simply get one of the opened documents on the screen.

Do you have anymore suggestion? Thanks.

Ok... I think I misunderstood your orignal question. You're having
problems getting the currently active doucment, not getting a running
instance of word....

Hmmm, sorry - i'm going ot have to think about that one.
 

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