Chargement automatique d'un Addin dans Excel

Résolu
s_kashiew Messages postés 5 Date d'inscription vendredi 7 janvier 2005 Statut Membre Dernière intervention 26 novembre 2008 - 5 mars 2007 à 03:47
s_kashiew Messages postés 5 Date d'inscription vendredi 7 janvier 2005 Statut Membre Dernière intervention 26 novembre 2008 - 5 mars 2007 à 09:46
Salut,
J'aimerai faire un chargement automatique d'un addin a l'ouverture d'un Excel.
Voici comment je procede:

    '.:: Open Excel ::.
    Set ExcelWbk = ExcelApp.Workbooks.Open(XlsFileName)
    For Each ArmAddin In ExcelApp.AddIns
        If ArmAddin.Name = "AddinName" Then
            FlagArmAddin = True
        End If
    Next
   
    '.:: Add Addin ::.
    If FlagArmAddin = True Then
        If ExcelApp.AddIns("AddinName").Installed = False Then
            ExcelApp.AddIns("AddinName").Installed = True
        End If
    Else
        ExcelApp.AddIns.Add(Path, True).Installed = True
    End If

A la premiere execution, il commence par me dire ExcelApp.AddIns("AddinName").Installed = True alors que lors d'un pas a pas, dans le menu des Addins, mon Addin n'est pas charge.

Donc j'ai force Excel en mettant
'.:: Add Addin ::.

    If FlagArmAddin = True Then

        ExcelApp.AddIns("AddinName").Installed = False

        ExcelApp.AddIns("AddinName").Installed = True

    Else

        ExcelApp.AddIns.Add(Path, True).Installed = True

    End If
Et la, pour la ligne ExcelApp.AddIns("AddinName").Installed = True il me met
    Run-time error '1004':
    Unable to set the Installed property of the Addin class.

Quelqu'un pourrait-il m'aider ?
Merci.

3 réponses

s_kashiew Messages postés 5 Date d'inscription vendredi 7 janvier 2005 Statut Membre Dernière intervention 26 novembre 2008
5 mars 2007 à 09:46
Salut, en fait j'ai contourne le pb en utilisant la methode RegisterXll de ls classe Application.
Merci.
3
mortalino Messages postés 6786 Date d'inscription vendredi 16 décembre 2005 Statut Membre Dernière intervention 21 décembre 2011 18
5 mars 2007 à 08:40
Salut,

je t'ai fait qques modifs de rien du tout, et je viens de tester avec une de mes macro complémentaire et ça fonctionne bien :

Option Explicit

Private Sub Form_Load()
        Dim ExcelApp As Excel.Application
        Dim ExcelWbk As Excel.Workbook
        Dim ArmAddin As Excel.AddIn
        Dim FlagArmAddin As Boolean
        
    Set ExcelApp = New Excel.Application
        

    Set ExcelWbk = ExcelApp.Workbooks.Open("C:\Documents and
settings\mortalino\Bureau\Classeur1.xls")
    ExcelApp.Visible = True
    For Each ArmAddin In ExcelApp.AddIns
        If ArmAddin.Name = "Fonctions_Nico.xla" Then ' rajoute l'extension ICI
            FlagArmAddin = True: Exit For 'modif ICI (il faut sortir de la boucle,
        End If ' sinon ton flag repassera à
False étant
    Next '
donné qu'il y'a peut-être d'autres *.xla
    
   
    '.:: Add Addin ::.
    If FlagArmAddin = True Then
        If ExcelApp.AddIns("Fonctions_Nico").Installed = False Then
            ExcelApp.AddIns("Fonctions_Nico").Installed = True
        End If
    Else
        ExcelApp.AddIns.Add("C:\Documents and
settings\mortalino\Bureau", True).Installed = True
    End If

' *** INUTILE POUR LE RESTE...

End Sub


~ <small>[code.aspx?ID=39466 Mortalino] ~
Colorisation automatique</small>

@++

<hr size="2" width="100%" />
  --Mortalino--
Le mystérieux chevalier, "Provençal, le Gaulois"
<!--
0
mortalino Messages postés 6786 Date d'inscription vendredi 16 décembre 2005 Statut Membre Dernière intervention 21 décembre 2011 18
5 mars 2007 à 08:44
Arghh, petite erreur de ma part ici :

    '.:: Add Addin ::.
    If FlagArmAddin = True Then
        If ExcelApp.AddIns("Fonctions_Nico").Installed = False Then
            ExcelApp.AddIns("Fonctions_Nico").Installed = True
        End If
    Else
        ExcelApp.AddIns.Add("C:\Documents and
settings\mortalino\Bureau\NomAddin.xla", True).Installed = True
'         oublie ici du nom
^^
    End If

~ <small>[code.aspx?ID=39466 Mortalino] ~
Colorisation automatique</small>

@++

<hr size="2" width="100%" />
  --Mortalino--
Le mystérieux chevalier, "Provençal, le Gaulois"
<!--
0
Rejoignez-nous