Swicthing Between Open Word documents (VB.NET)

B

bannp

Hi All,

I'm writing a project in VB.NET that needs to copy some information
from an open word. The open word document has already been opened on
the workstation by another application. I want my program to be able to
see the open word document and copy the contents of the open Word
document to another word document. So far it looks like this:

Dim word As New Microsoft.Office.Interop.Word.Application
Dim doc As New Microsoft.Office.Interop.Word.Document

Try
doc = word.Documents.open("Need to insert already open word
document)

doc.Activate()
Catch ex As COMException
MessageBox.Show(ex.Message)
End Try

I have tried using the GetObject function in VB.NET but I keep getting
an Active X Error. Any body got any ideas how I could achive this.

Thanks,

Pete
 
P

Perry

If the purpose is merely to copy the content of the Word document, you can
switch to
adding a document (rather than opening) using the source (opened or not)
document as "template"

Your code would roughly come down to
(Assuming you have opened the Interop class by using the Imports clause on
top)

dim wd as New Word.Application
Dim doc as New Word.Document
try
doc = wd.Documents.add("your template.dot")
doc.Activate
catch
...etc

Krgrds,
Perry
 

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