Custom Task Panes

Today we have a guest post from Kevin Boske, a program manager on the Office Programmability team.  Kevin discusses a feature that will make it much easier for developers to add their own task panes to Office, so while the example presented here is in Excel, the same thing is possible in Word, PowerPoint, etc.  Kevin also writes a blog on Office development.

Prime Real Estate In Office

With UI, like in real-estate, it’s all about location, location, location.  Previous versions of Office provided limited real estate to display custom application features.  And, like the Seattle housing market, developers looking to build custom UI find that space is at a premium.  For some time now, Office developers have found methods to build custom UI, but never in the application’s main window.  CommandBars were programmable from their inception, but were restricted to controls, kinda like those condos going in up the street from my house – functional, but they all start to look alike after a while.

Windows in Condos

Condos in Windows?

Office 2003 introduced SmartDocuments and Action Panes for Word and Excel, but these were carried in the document, sort of like a craftsman home, but on wheels.

Application-scoped add-ins with custom UI never really got past the permitting process until now – enter Custom Task Panes (CTP).  Finally, the developer can build that custom dream home, right in that desirable neighborhood with the good schools and within walking distance to grocery and coffee shop.

Custom Task Panes

In Office 2007, we add support for application-scoped, programmable UI in the main application window through Custom Task Panes.  CTP’s are COM Add-Ins for Outlook, InfoPath, Word, Excel, Access or PowerPoint.  CTPs are built on the same technology as the other Task Panes in Office, such as Research and Shared Workspaces. 

(The Research Task Pane in Excel – Click to enlarge)

A Custom Task Pane can sit in the client window either docked or free-floating, and can surface custom-branded UI in the form of an ActiveX control.  For example, the following CTP was written in C# and hosts a managed ActiveX control that captures the BeforeSave event to set the location where the save will occur:

(A Custom Task Pane in Excel 2007)

Just like an Office COM Add-In, the CTP must implement IDTExtensibility2.  In addition, CTPs must implement ICustomTaskPaneConsumer.  This interface has one method:  CTPFactoryAvailable, which must be called after the Add-In’s IDTExtensibility2::OnConnection.  CTPFactoryAvailable passes a CTPFactory to the add-in, which can be used to create the CTP for the life of the add-in.  This design makes it easy to implement a CTP in .NET as a shared add-in, as shown by Ted Pattison in this Channel9 screencast.   Kathleen McGrath from the VSTO team also describes how to build a CTP.  Mark O’Hara and Frank Rice have some more information on how to build a CTP on MSDN.

The code for the Workbook Saver Task Pane is relatively simple.  I’ve attached it here, so that you can download MyCustomTaskPane.txt and review it. 

Speaking of real-estate, anyone in the market for a two-bedroom Cape Cod in NE Seattle?