Automating existing instances of word ?

A

Andrew Kennard

Hi all

I'm trying to automate Word from another application

After creating the Application object, Documents Collection and Document
object. These objects only seem to know about the stuff i've just created
within that app ? ie if word was already open and had three docs open they
don't seem to be in the documents collection ?

The app is not written in VB but a VB example would be good .... or am I
doing something wrong ?

TIA

Andrew
 
P

Perry

I've answered a more/less similar question some time ago, contents of which
betwix <q> and <unq>
and I've got you an URL with some other code that might help you

the URL:
http://word.mvps.org/faqs/interdev/controlwordfromxl.htm


the Previous Msg:
Obviously I have Word set to the (more or less) equivalent of classic MDI,
each instance in its own window.


If you´ve coded correctly, you can quit each object variable pointing to a
newly created
Word instance seperately.

This is a sequence within Word VBA (!) examplifying object orientated coding
in which
each instance can be addressed seperately and in yr case: killed seperately:
(actually a bit of "inter appliation" automation ... oops that didn't sound
too good, now did it? ....)


Dim Inst1 As New Word.Application
Dim Inst2 As New Word.Application
Dim Doc1 As Document
Dim Doc2 As Document


Inst1.Visible = True
Inst2.Visible = True


Set Doc1 = Inst1.Documents.Add
Set Doc2 = Inst2.Documents.Add


Doc1.Windows(1).Visible = True
Doc2.Windows(1).Visible = True


Doc1.Range(0, 0).InsertAfter "text in doc1"
Doc2.Range(0, 0).InsertAfter "text in doc2"


Doc1.Close 0
Inst1.Quit: Set Inst1 = Nothing


'Now all actions of Inst1 are processed, leaving you Inst2 with document and
the text to proof this.
' Note: all other previsouly instances of Word should be intact as well !


--


<unq>




--
Krgrds,
Perry

System:
Vista/Office Ultimate
VS2005/VSTO2005 SE
 
A

Andrew Kennard

Thanks Perry thanks got me on the right track !


Perry said:
I've answered a more/less similar question some time ago, contents of
which betwix <q> and <unq>
and I've got you an URL with some other code that might help you

the URL:
http://word.mvps.org/faqs/interdev/controlwordfromxl.htm


the Previous Msg:



If you´ve coded correctly, you can quit each object variable pointing to a
newly created
Word instance seperately.

This is a sequence within Word VBA (!) examplifying object orientated
coding
in which
each instance can be addressed seperately and in yr case: killed
seperately:
(actually a bit of "inter appliation" automation ... oops that didn't
sound
too good, now did it? ....)


Dim Inst1 As New Word.Application
Dim Inst2 As New Word.Application
Dim Doc1 As Document
Dim Doc2 As Document


Inst1.Visible = True
Inst2.Visible = True


Set Doc1 = Inst1.Documents.Add
Set Doc2 = Inst2.Documents.Add


Doc1.Windows(1).Visible = True
Doc2.Windows(1).Visible = True


Doc1.Range(0, 0).InsertAfter "text in doc1"
Doc2.Range(0, 0).InsertAfter "text in doc2"


Doc1.Close 0
Inst1.Quit: Set Inst1 = Nothing


'Now all actions of Inst1 are processed, leaving you Inst2 with document
and
the text to proof this.
' Note: all other previsouly instances of Word should be intact as well !


--


<unq>




--
Krgrds,
Perry

System:
Vista/Office Ultimate
VS2005/VSTO2005 SE
 

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