MS Word custom taskbar disappears when I open a document programmatically

I am trying to create a simple MS Word add-on (mainly for learning functionality). The application adds a custom taskbar and is grouped into a feed. Ribbon controls include a flag to control the visibility of a custom task pane and a button to open a document. When I test the addon in MS Word, the taskbar displays correctly and the checkbox works correctly. The problem is that as soon as I click the button and open a new document, the taskbar is hidden and the checkbox no longer controls the visibility of the taskbar. What is going wrong? How to save the displayed taskbar?

Here is a simple version of addin:

public partial class ThisAddIn { private MyUserControl _myUserControl; private CustomTaskPane _myCustomTastPane; private OpenFileDialog _dialog; private void ThisAddIn_Startup(object sender, System.EventArgs e) { _dialog = new OpenFileDialog { Filter = "Doc File (*.rtf)|*.rtf", RestoreDirectory = true }; _myUserControl = new MyUserControl(); _myCustomTastPane = this.CustomTaskPanes.Add(_myUserControl, "My Task Pane"); _myCustomTastPane.Visible = true; Globals.Ribbons.MyRibbon.ShowPane.Click += ShowClicked; Globals.Ribbons.MyRibbon.LoadDoc.Click += LoadFile; } private void ShowClicked(object sender, RibbonControlEventArgs ribbonControlEventArgs) { _myCustomTastPane.Visible = Globals.Ribbons.MyRibbon.ShowPane.Checked; } void LoadFile(object sender, RibbonControlEventArgs e) { if (_dialog.ShowDialog() != DialogResult.OK) return; object missing = Missing.Value; object myFalse = false; object myTrue = true; object format = WdSaveFormat.wdFormatRTF; object fileToOpen = _dialog.FileName; Application.Documents.Open(ref fileToOpen, ref myFalse, ref myFalse, ref myFalse, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref myTrue, ref myFalse, ref missing, ref missing, ref missing); } private void ThisAddIn_Shutdown(object sender, System.EventArgs e) { } #region VSTO generated code //.... #endregion } 

To keep things simple, I didn’t use the definition of the ribbon, as this is really a button and a checkbox. I also do not take into account the definition of MyUserControl, because the contents of the class are not very important (in my demo version I just have a simple class with a label).

+5
ms-word vsto add-in
source share
1 answer

In MS Word, Custom taskbar is a window for each document ( see MSDN link ). If you open a new document, the taskbar collection is different. If you want to keep the permanent taskbar open, you will have to manage it yourself, tracking the events of opening and closing the document, as described below.

From MSDN ...

When you create a custom taskbar for Word 2007 or InfoPath 2007, the taskbar appears for only one document . The taskbars in these applications are associated with the window in which documents are stored, but for each document there is another instance of this window.
...
If you want to display a custom taskbar for multiple documents, you can create a new instance of the custom task pane when the user creates a new document or opens an existing document. For example, you can create handlers for NewDocument or DocumentOpen events in the Word 2007 add-in to create a new instance of the custom task NewDocument that is visible with a new or open document.

+6
source share

All Articles