Accessing Task Pane from another Task Pane in Excel

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

Accessing Task Pane from another Task Pane in Excel
Trying to close Task Pane2 when a button is clicked on Task Pane 1 in Excel 
Peter Baddeley




Posts: 7
Joined: 2010-07-20
I have been round and round on this one and need some help please.
I have searched everywhere watched every video and checked every sample !

All the samples show open and closing taskpanes from the AddinModule - that works for me too using:

AdxExcelTaskPanesCollectionItem2.TaskPaneInstance.Visible = Not AdxExcelTaskPanesCollectionItem2.TaskPaneInstance.Visible

And i can get the form/task pane to close itself from a button click :

Dim TaskPane As AddinExpress.XL.ADXExcelTaskPane = Item.TaskPaneInstance
TaskPane.Visible = False

BUT and a BIG BUT
No matter what i try I cannot get code in the TaskPane 1 to close TaskPane2
I have dimmed, cast everything and no combinations work
The most common error i get (one of many) is:

Type 'ADXExcelTaskPanesCollectionItem1.TaskPaneInstance' is not defined. or something similar

thanks for your help
Posted 20 Jul, 2010 00:39:28 Top
Andrei Smolin


Add-in Express team


Posts: 14114
Joined: 2006-05-11
Hi Peter,

ADXExcelTaskPane provides the AddinModule property. You cast it to the type of your add-in module (MyAddin1.AddinModule, for instance) and then access the manager's collection item.

Regards from Belarus (GMT+2),

Andrei Smolin
Add-in Express Team Leader
Posted 20 Jul, 2010 04:12:11 Top
Peter Baddeley




Posts: 7
Joined: 2010-07-20
Andrei

Thanks for the quick response

I tried to do something like that but still came up with errors
(says it is not 'declared' in the TaskPane1 )

Please could you give me a piece of code?

thanks
Posted 20 Jul, 2010 08:39:41 Top
Fedor Shihantsov


Add-in Express team


Posts: 1188
Joined: 2005-01-11
Hi Peter,

Please see a couple of ways:


Public Class ADXExcelTaskPane1
    Inherits AddinExpress.XL.ADXExcelTaskPane
    ...

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim TaskPane As AddinExpress.XL.ADXExcelTaskPane = Me.ExcelTaskPanesManager.Items(1).TaskPaneInstance
        If (TaskPane IsNot Nothing) Then
            TaskPane.Hide()
        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        TryCast(Me.AddinModule, AddinModule).AddinModuleCloseTaskPaneMethod()
    End Sub
End Class

Public Class AddinModule
    Inherits AddinExpress.MSO.ADXAddinModule
    ... 
    Public Sub AddinModuleCloseTaskPaneMethod()
        Dim TaskPane As AddinExpress.XL.ADXExcelTaskPane = AdxExcelTaskPanesCollectionItem2.TaskPaneInstance
        If (TaskPane IsNot Nothing) Then
            TaskPane.Hide()
        End If

    End Sub

End Class


You can download this sample.
Posted 21 Jul, 2010 07:45:13 Top
Peter Baddeley




Posts: 7
Joined: 2010-07-20
Stunning

Thanks guys - I would never have got it - but your code has taught me a lot

I will give it a go

BIG thanks
Posted 21 Jul, 2010 09:51:45 Top