win32com: how to connect to a specific instance of a runningobject?

Terry Reedy tjreedy at udel.edu
Fri Jun 2 15:15:37 EDT 2006


"ago" <xivulon at gmail.com> wrote in message 
news:1149273628.486179.224680 at h76g2000cwa.googlegroups.com...
> 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

Perhaps you can submit this to the Python Cookbook at oreilly.com (sp?)







More information about the Python-list mailing list