instantiate multiple automation objects

Roger Upole rupole at compaq.net
Sun Jun 4 11:18:26 EDT 2000


win32com.client.Dispatch always tries to connect to a running
instance first, so if you've already done a Dispatch for that
object, any subsequent call will return the same instance.
However, you could use DispatchEx to get a second
instance, as it apparently doesn't try to connect to a running
instance first.
           HTH
                  Roger Upole


"Yoon S. Choi" <ychoi at pipeline.com> wrote in message
news:3939d663.1392772 at nntp.pipeline.com...
> I am trying (without much luck) to create multiple instances of an
> automation object.  I can create 1 instance correctly using the
> function call win32com.client.Dispatch().  However, when I use the
> same function to try and create another automation object, it just
> refers to the first instance.
>
> Here is an example using Microsoft Word as the automation object:
>
> import win32com.client
> w1 = win32com.client.Dispatch( "Word.Application")
> w2 = win32com.client.Dispatch( "Word.Application")
> w1.Visible = 1  # Microsoft Word becomes visible
> w2.Visible = 1  # Nothing happens because w2 is referring to the same
> object as w1
>
> How can I for example create another instance of Microsoft Word?  In
> other words, w1 and w2 would refer to two separate automation objects
> of the same type.
> Can I do this without having to resort directly to the pythoncom
> module and its associated CoCreateInstance and CoGetClassObject
> functions?





More information about the Python-list mailing list