tags:

views:

406

answers:

2

Hi, We are currently working on creating an ActiveX dll for migrating our existing xlt template file. For this we tried creating an ActiveX dll in VB6. We were successful in creating the Add-Ins but we are facing a serious issue.

The AddinInstance_OnConnection is being called indefinitely leading to creation of multiple excel objects. As this is the primary method that gets called when the host application creates the Add-Ins we are not able to stop this execution.

Can anyone please provide us some suggestion for the above problem.

Thanks in advance

ram

+1  A: 

I had a similar problem one time and I resolved it creating an ActiveX EXE that it's the caller of the main application in the Active DLL.

You keep a reference in the EXE to the main application in the DLL and you handle it like:

If IsNull(ReferenceToDll) Then
    CreateDllApplication
Endif

RunDllApplication
Patrizio Rullo
A: 

Thanks! but i am not able to resolve this still. I tried executing step by step. If i have only the msgbox statement it works fine but when some control is added or some iteration like foreach myworks in application.workbook is done this method gets indefinite call leading to idefinite number of excel object created. Does it mean that we cannot create a control using this activeX dll here.

Can you please have a look of the code below and give me some suggestion

Private Sub AddinInstance_OnConnection(ByVal Application As Object, ByVal ConnectMode As AddInDesignerObjects.ext_ConnectMode, ByVal AddInInst As Object, custom() As Variant)

MsgBox "AddinInstance_OnConnection"

'Code to create control

'Set CBar = CommandBars("Simple AddIns")

Set CBar = CommandBars.Add(Name:="Simple AddIns Toolbar", Position:= _

        msoBarFloating)

     CBar.Visible = True

 Set CBarCtl = CBar.Controls.Add(Type:=msoControlButton)

With CBarCtl

    .FaceId = 23

    .Caption = "Show Message"

    .ToolTipText = "Welcomes the user"

    .OnAction = "showMessage"

End With

Set excelapp = Application

End Sub

Also please let me know where I am doing a mistake.

Thanks,

ram