using an already running COM object with Dispatch

J

jiccab

Greetings.

with the following code,

olApp = Dispatch("Outlook.Application")

I am capable of getting a new instance of Outlook running. I would
like to be able to use the instance that is already running, if exists,
otherwise open a new one.

Has anyone being able to do this?
 
R

Roger Upole

jiccab said:
Greetings.

with the following code,

olApp = Dispatch("Outlook.Application")

I am capable of getting a new instance of Outlook running. I would
like to be able to use the instance that is already running, if exists,
otherwise open a new one.

Has anyone being able to do this?

You should be able to use
win32com.client.GetActiveObject('outlook.application')
and fall back to a normal Dispatch if it fails.

Roger
 
J

jiccab

Roger said:
You should be able to use
win32com.client.GetActiveObject('outlook.application')
and fall back to a normal Dispatch if it fails.

Roger

Yes indeed. Thanks. here is the code:

from win32com.client.dynamic import Dispatch
from win32com.client import GetActiveObject

def OutlookPointer():
try:
olApp = GetActiveObject("Outlook.Application")
except:
olApp = Dispatch("Outlook.Application")
return olApp

op = OutlookPointer()
 

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

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top