win32com: how to connect to a specific instance of a running object?

ago xivulon at gmail.com
Fri Jun 2 14:40:28 EDT 2006


solved, if it can be useful to others here is my code:

import pythoncom
import win32com.client

def getWorkbook(workbookName):
	lenstr = len(workbookName)
	workbook = None
	rot = pythoncom.GetRunningObjectTable()
	rotenum = rot.EnumRunning()
	while True:
		monikers = rotenum.Next()
		if not monikers: break
		ctx = pythoncom.CreateBindCtx(0)
		name = monikers[0].GetDisplayName(ctx, None);
		if name[-lenstr:] == workbookName:
			obj = rot.GetObject(monikers[0])
			workbook =
win32com.client.Dispatch(obj.QueryInterface(pythoncom.IID_IDispatch))
	return workbook




More information about the Python-list mailing list