Custom Task Panes in Microsoft VSTO "v3" June CTP

Download this episode

Download Video

Description

Learn how to create an add-in for Microsoft Excel 2007 using the June CTP of Visual Studio Tools for Office "v3" and how to customize the application-level custom task pane. This tutorial demonstrates how to add controls to the custom task pane that interact with the Excel workbook, and how to create multiple custom task panes for your solution.

Tags:

MS Office, Office

Embed

Format

Available formats for this video:

Actual format may change based on video formats available and browser capability.

    The Discussion

    • User profile image
      Christin
      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

    Comments closed

    Comments have been closed since this content was published more than 30 days ago, but if you'd like to send us feedback you can Contact Us.