How to access Workbook for Advanced Taskpane in Excel 2016 (SDI)?

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

How to access Workbook for Advanced Taskpane in Excel 2016 (SDI)?
 
gjvdkamp




Posts: 56
Joined: 2018-08-28
Hi,

I have a COM addin for Excel with Advanced taskpanes.

I need to get the workbook for the window the taskpane is shown for (SDI).
I have a class MyTaskPane that derives from ADXExcelTaskPane, for every new workbook this gets instantiated (async from wokbook.open it appears..)

I tried accessing the WindowObj in the constructor of MyTaskPane, but that throw a null expcepetion (it doesn't just return null...).

How can I get the workbook the current Advanced Taskpane is 'associated with'?

Right now my setup is a little klunky looking at ExcelApp.ActiveWorkbook b/c I had to support 2010 MDI before, but running into some isssues with that now, was hoping there might be a more robust way.
Posted 11 Oct, 2019 03:34:53 Top
Andrei Smolin


Add-in Express team


Posts: 18825
Joined: 2006-05-11
Hello gjvdkamp,

You should get ADXExcelTaskPane.WindowObj in the ADXExcelTaskPane.ADXTaskPaneBeforeShow. You may need to reverse your logic: you can switch from controlling the pane from the add-in module's events to letting the form react to events, including events raised by the module. In this case, you won't need to do anything in the constructor of the add-in module.


Andrei Smolin
Add-in Express Team Leader
Posted 11 Oct, 2019 04:11:15 Top
gjvdkamp




Posts: 56
Joined: 2018-08-28
Got it thx

private void MessageNavigatorTaskPane_ADXBeforeTaskPaneShow(object sender, ADXBeforeTaskPaneShowEventArgs e) {
var o = WindowObj as Microsoft.Office.Interop.Excel.Window;
var wb = o.Parent as Microsoft.Office.Interop.Excel.Workbook;
}
Posted 11 Oct, 2019 04:26:23 Top
Andrei Smolin


Add-in Express team


Posts: 18825
Joined: 2006-05-11
Welcome!


Andrei Smolin
Add-in Express Team Leader
Posted 11 Oct, 2019 06:17:34 Top