Glen Griesel
Guest
|
The problem referred to in this thread is very similar to that contained in blue
We have another COM Addin in Excel that is set to Load On Demand.
The AddIn tracks the ADXExcelAppEvents.WorkbookOpen Event.
The Addin now loads perfectly using build 4351.
However when a second workbook is opened in Office 2016 ( not sure about 2010 ) and the ADXExcelAppEvents.WorkbookOpen event is fired we find that the Object reference to the current taskpaneinstance IS Nothing ( = null C#) which is not correct.
Our event code is as follows
Public Class AddinModule
Inherits AddinExpress.MSO.ADXAddinModule
Friend WithEvents aixExcelEvents As AddinExpress.MSO.ADXExcelAppEvents
Private Sub aixExcelEvents_WorkbookOpen(sender As Object, _
hostObj As Object) Handles aixExcelEvents.WorkbookOpen
Dim oTPInstance() As OurTaskPaneClassName
'*> get a reference to the current taskpane instance
oTPInstance = CType(OurTaskPaneClassName.TaskPaneInstance, OurTaskPaneClassName)
'[ at this point oTPInstance Is Nothing - Wrong !
' get the task pane to do something
oTPInstance.SayHelloWorld
End Sub
End Class
Given that the Addin is already loaded when the second Workbook is opended, it follows that the current TaskPaneInstance must be a valid object reference and cannot be Nothing (null).
Can you please look into this matter in the same way that you did in thread 13651.
Best Regards |
|
Andrei Smolin
Add-in Express team
Posts: 18821
Joined: 2006-05-11
|
Hello Glen,
Add-in Express forms are built on tracing the window system of the host application. That is, for a pane to be shown in a given region, certain host application windows must be shown first. When these windows get shown, Add-in Express intercepts the corresponding window messages and embeds your form (by issuing a number of other window messages).
The main point is: the mechanism above may not (and typically does not) correspond to the events raised by the object model of the host application. In other words, if you use a certain event of the object model to check an existence of a form instance in a given region(s), the result may be different for different Office versions (and even different builds of the same Office version), different startup scenarios, etc. Also, we fix our errors and this may also influence the result.
That is, the WorkbookOpen (and any other) event may be fired when Add-in Express panes are *not* created yet.
Note that your code works in the context of an event of the host application's object model. You can bypass the issue if you let your code work in the context of the pane. Specifically, you can use the ADXExcelTaskPane.ADXBeforeTaskPaneShow event. The event occurs after a pane instance for the corresponding region is created before the pane instance is shown (FYI, you can control the visibility of the pane instance in this event ?Â?Ð?ã just set ADXExcelTaskPane.Visible = false to prevent the pane instance from showing up). Intercepting this event allows you to get notified about existence of a pane instance in the corresponding region.
Andrei Smolin
Add-in Express Team Leader |
|
Glen Griesel
Guest
|
Hi Andrei
Thank you for the very interesting and informative feedback.
Definite material for the Add-in Express Tips and Notes section of the Addin Express Help File in my view.
I get what you are saying and so we are going to refactor some of our code around your recommendations and I will post back in a few days.
Great support from AIX, as usual.
Best Regards
Glen |
|
Andrei Smolin
Add-in Express team
Posts: 18821
Joined: 2006-05-11
|
You are welcome!
Andrei Smolin
Add-in Express Team Leader |
|