Excel add-in não carregando ao abrir o Excel a partir do VBA

1

Estou usando o suplemento reg-ex do excel e ele funciona bem, o único problema com ele que não carrega quando o Excel é iniciado pelo VBA.

Eu tenho uma macro em word para coletar alguns dados no Word e copiá-los para o Excel, este começa a ser excel, a saída é boa, mas eu preciso reiniciar o Excel para poder usar o add-in nas opções, apenas não carregando).

Eu tentei outra macro: basta abrir o Excel e criar uma nova pasta de trabalho e ela tem o mesmo problema.

Eu tenho apenas este suplemento de terceiros, portanto não posso comparar com outros.

Alguma ideia?

    
por Máté Juhász 18.05.2015 / 09:34

2 respostas

0

Eu o resolvi com base na resposta postada para uma pergunta semelhante no stackoverflow: link

I looked into this problem again, and the Application.Addins collection seems to have all the addins listed in the Tools->Addins menu, with a boolean value stating whether or not an addin is installed. So what seems to work for me now is to loop through all addins and if .Installed = true then I set .Installed to False and back to True, and that seems to properly load my addins.

Function ReloadXLAddins(TheXLApp As Excel.Application) As Boolean

    Dim CurrAddin As Excel.AddIn

    For Each CurrAddin In TheXLApp.AddIns
        If CurrAddin.Installed Then
            CurrAddin.Installed = False
            CurrAddin.Installed = True
        End If
    Next CurrAddin

End Function
    
por 01.09.2016 / 13:25
1

É assim que deve funcionar.

De documentos COM.

      Component Automation  
Exposing the Application Object  

 Language Filter: All Language Filter: Multiple Language Filter: Visual Basic Language Filter: C# Language Filter: C++ Language Filter: J# Language Filter: JScript  
 Visual Basic (Declaration) 
 Visual Basic (Usage) 
 C# 
 C++ 
 J# 
 JScript 

Any document-based, user-interactive applications that expose ActiveX objects should have one top-level object named the Application object. This object is initialized as the active object when an application starts.

The Application object identifies the application and provides a way for ActiveX clients to bind to and navigate the application's exposed objects. All other exposed objects are subordinate to the Application object; it is the root-level object in the object hierarchy.

The names of the Application object's members are part of the global name space, so ActiveX clients do not need to qualify them. For example, if MyApplication is the name of the Application object, a Visual Basic program can refer to a method of MyApplication as MyApplication.MyMethod or simply MyMethod. However, you should be careful not to overload the Application object with too many members because it can cause ambiguity and decrease performance. A large, complicated application with many members should be organized hierarchically, with a few generalized objects at the top, branching out into smaller, more specialized objects. 

The following chart shows how applications should expose their Application and Document objects.

Command line  Multiple-document interface application  Single-document interface application  
/Embedding 
 Expose class factories for document classes, but not for the application.

Call RegisterActiveObject for the Application object.
 Expose class factories for document class, but not for the application.

Call RegisterActiveObject for the Application object.

/Automation 
 Expose class factories for document classes.

Expose class factory for the application using RegisterClassObject.

Call RegisterActiveObject for the Application object.
 Do not expose class factory for document class.

Expose class factory for the Application object using RegisterClassObject.

Call RegisterActiveObject for the Application object.

No OLE switches 
 Expose class factories for document classes, but not for the application.

Call RegisterActiveObject for the Application object.
 Call RegisterActiveObject for the Application object. 


The call to RegisterActiveObject enters the Application object in OLE's running object table (ROT), so ActiveX clients can retrieve the active object instead of creating a new instance. Visual Basic applications can use the GetObject statement to access an existing object.

 © Microsoft Corporation. All rights reserved. 

Assim, o / a ou o / embedding não carregará nada, exceto o aplicativo simples (e / a também é uma boa etapa de solução de problemas).

Inicie seu aplicativo e, em seguida, GetObject nele.

Além disso, há poucas razões para usar, como addin, como você pode fazer a coisa exata que o addin está fazendo. Isso é vbs (tão pastável no VBA) usando o mesmo mecanismo RegEx do seu suplemento (o Word também tem seu próprio mecanismo RegEx chamado Use Wildcards ). Defina uma referência para Microsoft VBScript Regular Expression 5.5 .

Set regEx1 = New RegExp
If Instr(LCase(Arg(1)), "i") > 0 then
    regEx1.IgnoreCase = True
Else
    regEx1.IgnoreCase = False
End If 
If Instr(LCase(Arg(1)), "v") > 0 then
    IncExc = False
Else
    IncExc = True
End If 
regEx1.Global = False
regEx1.Pattern = Pttn 
Do Until Inp.AtEndOfStream
    Line=Inp.readline
    If RegEx1.Test(Line) = IncExc then
        outp.writeline Line
    End If
Loop
    
por 22.05.2015 / 01:10