[python-win32] Re: Getting an Excel running instance

Roger Upole rwupole at msn.com
Wed Sep 7 14:30:53 CEST 2005


You should be able to reference it as self.Application.

    hth
       Roger


"Marco & Laura" wrote:
> Hi.
> I'm trying to implement an Excel add-in based on the demo I found in
> win32com/demos (excelAddin.py)
> The demo basically adds a CommandBar with a Button and register itself. 
> What
> I'm trying to do is change the OnClick event to perform some operation in
> the ActiveSheet of the Excel instance in which the Button is clicked on. 
> The
> relevant code snippet is then:
>
> def OnClick (self, button, cancel):
>    xl = win32com.client.Dispatch('Excel.Application')
>    <cut on the rest of the performed operations>
>
> It works fine if I have only one Excel instance running. If there are more
> instances, Dispatch invokes the first one, which is not necessarily the
> desired one.
>
> To work around, first I have tried to get a reference to the Application
> from the OnClick event, but I didn't be able to find any.
>
> After some googling, I've tried a less obvious way, querying the Running
> Object Table to get some reference about running instances. I manage to 
> get
> the monikers of running objects, but I don't know how - and if possible -
> pass them to a function to get the object by reference. So, I wonder if
> there is a more newbie-ish method to reach my goal.
>
> Any help, hint or pointers would be greatly appreciated.
>
> Regards,
> Marco 



More information about the Python-win32 mailing list