INFO: Customizing the Microsoft Office XP Task Pane
This article was previously published under Q288542
This article has been archived. It is offered "as is" and will no longer be updated.
Microsoft Office XP contains a new feature called the Task Pane. A Task Pane is a dockable dialog window that gives users a convenient way to use commands, gather information, and modify their documents. An Office Task Pane can contain one or more pages, and each page is broken up into sections.
Developers can programmatically manipulate the Task Pane to perform certain functions such as view the pane, dock or undock the window, and add custom information to the New Item page that is common among all Office XP applications.
The Office XP Task Pane is a special type of dockable CommandBar object. Only one task pane exists in each Office application and it can be accessed through the CommandBars collection under the name TaskPane. This CommandBar has a single control, which represents the active page. You can access a limited number of properties for the page by using this CommandBarControl. For example, to display the name for the current page in the Task Pane, you can use code such as the following:
In addition, most CommandBar customizations such as docking, height, width, and so forth, can be performed on the Task Pane itself. However, there are several things you cannot do with the Task Pane CommandBar object. Here are a few examples:
MsgBox "The Active Task Pane Page = " & _ Application.CommandBars("TaskPane").Controls(1).Caption
- Showing the Task Pane through the CommandBars collection fails unless it has been shown at least once because a pane must contain at least one page to be made visible, but the host application does not typically assign a default page until the user displays the pane once.
- Attempting to add a control to the Task Pane by using Commandbar.Controls.Add fails with the following error message:Run-time error: -2147467259 (0x80004005)You cannot add, edit, or remove pages from the Task Pane. You can, however, add new items to the New Item page by using the NewFile object (discussed later in this article).
- You cannot set the Enabled property.
- You cannot change the active page for the Task Pane through the CommandBar object (that is, you cannot switch from the New Item page to the Clipboard page and vice-versa). However, Microsoft Word 2002 offers a separate object (Application.TaskPanes) to let you select the current page for its Task Pane. Word is the only Office XP application that offers this capability.
Add Items to the New Item Task Pane PageThere is one Task Pane page that every Office XP application implements: the New Item page. This page corresponds to the File New dialog box in previous versions of Office. Office XP allows you to add or remove items on this page so that documents or templates you use most often can be added for quick reference. To do this programmatically, use the NewFile object that is exposed by each Office application.
To access the NewFile object, use one of the following properties that are available from the Application object. The property names differ depending on which Office application you are working in:
The NewFile object exposes two methods, Add and Remove, which let you add and remove specific items into sections on the File New page for that Office application. For example, the following code creates a new entry in the "New Document" section for Word's File New Task Pane page:
After you run this code, there is a new entry in the "New Document" Task Pane page that, when clicked, opens the file C:\NewDocument.doc. Following is equivalent code for Microsoft Excel 2002:
Sub AddNewDocToTaskPane() Application.NewDocument.Add FileName:="C:\NewDocument.doc", _ Section:=msoNew, DisplayName:="Look! My New Document option" With Application.CommandBars("Task Pane") .Visible = False .Visible = True End WithEnd Sub
NOTE: Toggle the Visible property of the Task Pane to refresh the view. If the Task Pane is visible while the New Item page is active, any changes you make through code are not seen until it is hidden and then made visible again.
Sub AddNewWorkbookToTaskPane() Application.NewWorkbook.Add FileName:="C:\NewWorkbook.xls", _ Section:=msoNew, DisplayName:="Look! My New Workbook option" With Application.CommandBars("Task Pane") .Visible = False .Visible = True End WithEnd Sub
You can add items to New Item pages in the other Microsoft Office XP applications as well. If you are automating the Task Pane to suit a custom application, be sure to remove any items you add by using the Remove method when they are no longer needed. The new items you add persist for that user after the application is closed.
For more information on using the Task Pane, see the Visual Basic for Applications (VBA) Online Help for the NewFile Object.
Article ID: 288542 - Last Review: 12/06/2015 00:28:46 - Revision: 3.2
Microsoft Office XP Developer Edition, Microsoft Excel 2002 Standard Edition, Microsoft PowerPoint 2002 Standard Edition, Microsoft Word 2002
- kbnosurvey kbarchive kbinfo kbprogramming KB288542