Excel advanced task pane creation

Add-in Express™ Support Service
That's what is more important than anything else

Excel advanced task pane creation
 
Bob Devine


Guest


While working on my re-structure from MDI to SDI Excel I've come across an inconsistency in the way Advanced Excel task panes are created in SDI Excel (i.e. v2016 and later). The first task pane instance of a specific type appears to be created before the first workbook is opened. This means that in the TaskPaneCreate event of the first instance there's no way to get a reference to the associated workbook - I have to use ADXAfterTaskPaneShow instead. For subsequent workbooks the associated instance is created after the workbook is opened/created and the workbook can be referenced in TaskPaneCreate. I'm using a central object list to manage task pane instances and it's not a show-stopper since I can use ADXAfterTaskPaneShow and TryGetValue using the workbook name, but it would be cleaner to be able to use TaskPaneCreate for all workbooks.

Cheers, Bob
Posted 20 Feb, 2020 12:18:37 Top
Bob Devine


Guest


Actually, this is a problem for me. I have different Excel workbook types with the task pane visibility dependent on the type (I store the type in a custom XML part). The only event in which I can control visibility is in ADXBeforeTaskPaneShow, but I can't get a reference to the workbook at this point. Any ideas?

Thanks, Bob
Posted 20 Feb, 2020 12:57:03 Top
Bob Devine


Guest


Ok found a workaround - I disable the task pane in the manager then enable it in the WorkbookActivate event. Getting messy but at least it works.

Cheers, Bob
Posted 20 Feb, 2020 14:26:26 Top
Andrei Smolin


Add-in Express team


Posts: 18821
Joined: 2006-05-11
Hello Bob,

Bob Devine writes:
The first task pane instance of a specific type appears to be created before the first workbook is opened.


This isn't an inconsistency. Add-in Express panes are built around the windowing of Excel, not around its object model. In your case, if ADXExcelTaskPane.WindowObj is null/Nothing, you do not let it show: set ADXExcelTaskPane.Visible = false in the ADXExcelTaskPane.ADXBeforeTaskPaneShow event. When the WorkbookOpen event occurs, you scan the task pane instances and call a method - e.g. ShowIfHidden() - and if the pane's Visible is false, call ADXExcelTaskPane.Show().


Andrei Smolin
Add-in Express Team Leader
Posted 21 Feb, 2020 06:06:48 Top
Bob Devine


Guest


Hi Andrei

I'd expect consistent Excel-window behaviour in the TaskPaneCreate event however. At the moment it's nil for the first workbook and assigned for all subsequent workbooks. In other words the first task pane shouldn't be created until the first workbook Window is created - which would in fact be more consistent with the notion of task panes being built around the windowing of Excel. Anyway, not a showstopper by any means!

Thanks, Bob
Posted 21 Feb, 2020 06:40:23 Top
Andrei Smolin


Add-in Express team


Posts: 18821
Joined: 2006-05-11
Hello Bob,

The point is: Excel windows aren't created consistently. As soon as a window is created, Add-in Express embeds a pane it it; the object model's event may fire before or after the pane is embedded; the pane is embedded before or after the object model completes changing the state of its objects. In other words, it occurs often that a Excel.Window object is available while the window showing the corresponding Excel objects isn't. In your case it works the other way round: the window is available while the Excel.Window object isn't.

BTW, you should be prepared to these scenarios:
- The user enables the add-in a while after Excel starts; this means, you can start with several windows opened.
- The {pane}.WindowObj returns an Excel.ProtectedViewWindow object.

In section Accessing a Form Instance; see the PDF file in the folder {Add-in Express}\Docs on your development PC, we provide a list of event in which getting the corresponding pane instance may return null/Nothing.


Andrei Smolin
Add-in Express Team Leader
Posted 21 Feb, 2020 06:50:17 Top
Bob Devine


Guest


Thanks again Andrei - great support as always.

Cheers, Bob
Posted 21 Feb, 2020 08:27:51 Top
Andrei Smolin


Add-in Express team


Posts: 18821
Joined: 2006-05-11
You are welcome!


Andrei Smolin
Add-in Express Team Leader
Posted 21 Feb, 2020 08:36:42 Top