Following is a snippet of code that I have been using to figure out if
an addin in installed.

        xlApp = win32com.client.dynamic.Dispatch('Excel.Application')
        xlApp.DisplayAlerts = 0
        xlApp.Interactive = 1
        if xlApp.Application.Addins.Count <= 0:
            print "Terminating: No add_ins are available"
            xlApp.quit
            return 0

        # Addin name should be Analysis ToolPak or Analys32
        lnAddins=0
        for ia in range(1, xlApp.Application.Addins.Count):
##            print xlApp.Application.Addins(ia).Title
##            print
str(string.lower(xlApp.Application.Addins(ia).Title)), "xx"
##            print
string.find(str(string.lower(xlApp.Application.Addins(ia).Title)),
"analysis toolpak")
            if
string.find(str(string.lower(xlApp.Application.Addins(ia).Title)),
"analysis toolpak") >= 0 or
string.find(string.lower(xlApp.Application.Addins(ia).Title),
"analys32") >= 0:
                lnAddins=ia

        print lnAddins
        if lnAddins==0:
            print "Terminating.  Analysis ToolPak or Analy32 addins are
not availabe"
            xlApp.quit
            return

        xlApp.Application.Addins(lnAddins).Installed = 0
        xlApp.Application.Addins(lnAddins).Installed = 1

Hussain


-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Tim Roberts
Sent: Wednesday, April 25, 2007 12:02 PM
To: Python-Win32 List
Subject: Re: [python-win32] excel xla runautomacros

mjohnson wrote:
> I am having a problem with an excel add-in which is installed via
> xlApp.Workbooks.Open("C:/Program
> Files/Program/XLOF32.xla").RunAutoMacros(1)
>
> I can then add the add-in and install it via
> xlApp.AddIns.Add ("C:/Program Files/Program/XLOF32.xla",True)
> xlApp.AddIns.Item(Index='Excel Functions').Installed=True
>
> My problem is that the macro may have already been run, which
> generates a dialog warning that it is already open.
>
> The question, is there a way of detecting whether the add-in is
> already open?

Well, xlApp.AddIns is a collection.  You should be able to query the
collection item by item and check to see whether the add-in is present.

I'm leaving the code as "an exercise for the reader", but something like
this should be possible:
    for addin in range( xlApp.AddIns.Count ):
        if xlApp.AddIns.item(addin).Filename???
I don't know exactly which property you'd need to query.

-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.

_______________________________________________
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Disclaimer

This e-mail and any attachments is confidential and intended solely for the use 
of the individual(s) to whom it is addressed. Any views or opinions presented 
are solely those of the author and do not necessarily represent those of 
Waterstone Capital Management, L.P and affiliates. If you are not the intended 
recipient, be advised that you have received this e-mail in error and that any 
use, dissemination, printing, forwarding or copying of this email is strictly 
prohibited. Please contact the sender if you have received this e-mail in 
error. You should also be aware that e-mails are susceptible to interference 
and you should not assume that the contents of this e-mail originated from the 
sender above or that they have been accurately reproduced in their original 
form. Waterstone Capital Management, L.P. and affiliates accepts no 
responsibility for information, or errors or omissions in this e-mail or use or 
misuse thereof. If in doubt, please verify the authenticity with the!
  sender.


_______________________________________________
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32

Reply via email to