Word 2016 / custom user pane / problem with multiple windows RRS feed

  • Question

  • Good evening,

    I have got a problem with a VSTO add-in for word. The add-in has a custom user pane which is added if a document is opened or new created:


    Public Class ThisAddIn
        Private myUserControl1 As System.Windows.Forms.UserControl
        Private WithEvents myCustomTaskPane As Microsoft.Office.Tools.CustomTaskPane


    Private Sub Application_OpenDocument(ByVal Doc As Word.Document) Handles Application.DocumentOpen
            myUserControl1 = New MyUserControl
            myCustomTaskPane = CustomTaskPanes.Add(myUserControl1, "RIS Export")
        End Sub

    Private Sub Applicaton_NewDocument(ByVal Doc As Word.Document) Handles Application.NewDocument
        myUserControl1 = New MyUserControl
        myCustomTaskPane = CustomTaskPanes.Add(myUserControl1, "RIS Export")
     End Sub


    Then there is a custom button in the ribbon to make the user pane visible:


    Imports System.Windows.Forms
    Public Class RibbonConvert
        Implements Office.IRibbonExtensibility
        Private ribbon As Office.IRibbonUI

    Public Sub OnActionTest3(ByVal control As Office.IRibbonControl)
            Dim pane = Globals.ThisAddIn.TaskPane

            With pane
                .DockPosition = Microsoft.Office.Core.MsoCTPDockPosition.msoCTPDockPositionLeft
                .Width = myTaskPaneWidth
                .Visible = True
                Call Log(1, pane.Visible)
            End With
        End Sub


    Most of the time the add-in works as expected: I can open documents or create new ones and in each of these documents I can toggle the user pane on (with the button ion the ribbon) and off (the X on the user pane) an on again. The user panes react independent so turn it on or off affects only the user pane in the active window.
    However, in some cases the add-in reacts different. If I click the ribbon button to make the user pane visible, nothing happens in the active windows. Instead a user pane is shown in another (non-active) window. If I close that user pane, go back to the first document and click the button again, I get the same result. If I close the document where the user pane was shown and click the ribbon button in the first document, an error occurs that the user pane was disposed.
    So, I have no idea what the problem is. Any help is very much appreciated.

    Thank in advance,

    Saturday, August 11, 2018 5:48 PM

All replies

  • I suspect the problem may come from this

         Dim pane = Globals.ThisAddIn.TaskPane

    Is TaskPane a class-level member of ThisAddin? How do you declare it and assign a value to it?

    My best guess, at this point, is that the wrong instance of a task pane is being retrieved, here.

    Cindy Meister, Office Developer/Word MVP, <a href="http://blogs.msmvps.com/wordmeister"> my blog</a>

    Sunday, August 19, 2018 10:52 AM