This is a fantastic demo showing how to create Custom Task Panes (CTP) in Excel 2007 Beta, using the VSTO Community Tech Preview (CTP).  Many of you probably tried the same technique with Word 2007 and found a little quirk in the product.  When you first start Word after adding your Task Pane, you see the Task Pane and it works great.  Woo Hoo!  Big Smile

Then if you open a document or start a new document, oops, no Task Pane!  What's up with that?  Mad

Word  uses a unique parent window for each Document, but Excel uses the same parent window for all Workbooks that you open or create.  Word and Excel have been different for years and years.  Let's not bother with asking why at this moment, and focus on how to make your Custom Task Pane appear with every Word document. 

To make your Custom Task Pane appear with every document, you would need to add a new task pane whenever a new Word parent window is created.  Here are the events you need to respond to:

void ThisApplication_DocumentOpen(Word.Document Doc)

{

   AddTaskPane(Doc.ActiveWindow);

}


void ThisApplication_WindowActivate(Word.Document Doc, Word.Window Wn)

{

   AddTaskPane(Wn);

}



Similarly, you should clean up on DocumentBeforeClose and WindowDeactivate. 

Adding your task pane is the same in Excel and Word using a few very easy calls.  However, you might want to check if you already have this task pane created in this window. 


private void AddTaskPane(Word.Window parentWindow)

   try

   {


   if (taskPane != null)

   {  if (taskPane.Window == parentWindow)

      {return;}

   }

   simpleControl = new SimpleControl();//user control

   taskPane = this.CustomTaskPanes.Add(simpleControl, "My TaskPane", parentWindow);


   }
   catch ...
}

Super simple.  Just requries a little knowledge of the quirks of Word parent windows.  Hope this helps all the Word 2007 developers out there! 

Christin Boyd  Cool
VSTO Developer Evangelist
Microsoft Corporation