Actions Pane Overview
An actions pane is a customizable Document Actions task pane that is attached to a specific Microsoft Office Word document or Microsoft Office Excel workbook. It is hosted inside the Office task pane along with other built-in task panes such as the XML Source task pane in Excel or the Styles and Formatting task pane in Word. You can use Windows Forms controls or WPF controls to design the actions pane user interface.
Applies to: The information in this topic applies to document-level projects for the following applications: Excel 2007 and Excel 2010; Word 2007 and Word 2010. For more information, see Features Available by Office Application and Project Type.
You can create an actions pane only in a document-level customization for Word or Excel. You cannot create an actions pane in an application-level add-in. For more information, see Features Available by Office Application and Project Type.
The actions pane differs from custom task panes. Custom task panes are associated with the application, not a specific document. You can create custom task panes in application-level add-ins for some Microsoft Office applications. For more information, see Custom Task Panes Overview.
For a related video demonstration, see How Do I: Use WPF Controls Inside an Excel Actions Pane?.
The actions pane is represented by the ActionsPane class. When you create a document-level project, an instance of this class is available to your code by using the ActionsPane field of the ThisWorkbook (for Excel) or ThisDocument (for Word) class in your project. To display the actions pane, add a Windows Forms control to the Controls property of the ActionsPane field. The following code example adds a control named actions to the actions pane.
The actions pane becomes visible at run time as soon as you explicitly add a control to it. After the actions pane is displayed, you can dynamically add or remove controls in response to the user's actions. Typically, you add the code to display the actions pane in the Startup event handler of ThisDocument or ThisWorkbook so that the actions pane is visible when the user first opens the document. However, you might want to display the actions pane only in response to a user's action in the document. For example, you might add the code to the Click event of a control on the document.
Adding Multiple Controls to the Actions Pane
If you are adding multiple controls to the actions pane, in most cases you should group the controls in a user control, and then add the user control to the Controls property. This process includes the following steps:
Create the user interface (UI) of the actions pane by adding an Actions Pane Control or User Control item to your project. Both of these items include a custom Windows Forms UserControl class. The Actions Pane Control and User Control items are equivalent; the only difference is their name.
Add Windows Forms controls to the UserControl by using the designer, or by writing code.
Add an instance of the custom user control to the controls that are contained in the ActionsPane field of the ThisWorkbook (for Excel) or ThisDocument (for Word) class in your project.
Although the ActionsPane class has a Hide method and a Visible property, you cannot remove the actions pane from the user interface by using any members of the ActionsPane class itself. Calling the Hide method or setting the Visible property to false hides only the controls on the actions pane; it does not hide the task pane.
To hide the task pane in your solution, you have several options:
For Word, set the Visible property of the TaskPane object that represents the Document Actions task pane to false. The following code example is intended to be run from the ThisDocument class in your project.
For Word or Excel, you can alternatively set the CommandBar.Visible property of the command bar that represents the task pane to false. The following code example is intended to be run from the ThisDocument or ThisWorkbook class in your project.
Clearing the Actions Pane When the Document is Opened
If the user saves the document while the actions pane is visible, the actions pane is visible every time the document is opened, whether or not the actions pane contains any controls. If you want to control when it appears, call the Clear method of the ActionsPane field in the Startup event handler of ThisDocument or ThisWorkbook to ensure that the actions pane is not visible when the document is opened.
Determining When the Actions Pane is Closed
There is no event that is raised when the actions pane is closed. Although the ActionsPane class has a VisibleChanged event, this event is not raised when the end user closes the actions pane. Instead, this event is raised when the controls on the actions pane are hidden by calling the Hide method or by setting the Visible property to false.
If the end user closes the actions pane, the user can display it again by performing one of the following procedures in the user interface (UI) of the application.
To display the actions pane by using the UI of Word or Excel
On the Ribbon, click the View tab.
In the Show/Hide group, click the Document Actions toggle button.
You can add multiple user controls to the actions pane and then write code to respond to events on the document by showing and hiding the user controls. If you map XML schema elements to your document, you can show certain user controls in the actions pane whenever the insertion point is inside one of the XML elements. For more information, see Walkthrough: Changing the Actions Pane According to User Context, How to: Map Schemas to Word Documents Inside Visual Studio, and How to: Map Schemas to Worksheets Inside Visual Studio.
You can also write code to respond to the events of any object, including host control, application, or document events. For more information see Walkthrough: Programming Against Events of a NamedRange Control.
The controls on the actions pane have the same data binding capabilities as controls on Windows Forms. You can bind the controls to data sources such as data sets, typed data sets, and XML. For more information, see Data Binding and Windows Forms.
You can bind controls on the actions pane and controls on the document to the same dataset. For example, you can create a master/detail relation between the controls on the actions pane and the controls on the worksheet. For more information, see Walkthrough: Binding Data to Controls on an Excel Actions Pane.
If you are using multiple user controls, you can write code to properly stack the user controls on the actions pane whether it is docked vertically or horizontally. You can set the stacking order of the user controls on the actions pane by using the StackStyle enumeration of the StackOrder property. For more information, see How to: Manage Control Layout on Actions Panes
Stack from the bottom of the actions pane.
Stack from the left of the actions pane.
Stack from the right of the actions pane.
Stack from the top of the actions pane.
No stacking order defined; order is controlled by the developer.
The following code sets the StackOrder property to stack the user controls from the top of the actions pane.
If the user resizes the actions pane at run time, the controls can resize with the actions pane. You can use the Anchor property of a Windows Forms control to anchor controls to the actions pane. You can also anchor the Windows Forms controls onto the user control in the same manner. For more information, see How to: Anchor Controls on Windows Forms.
You cannot directly change the size of an ActionsPane because the ActionsPane is embedded in the task pane. However, you can programmatically change the width of the task pane by setting the Width property of the CommandBar that represents the task pane. You can change the height of the task pane if it is docked horizontally or is floating.
Programmatically resizing the task pane is generally not recommended because the user should be able to select the task pane size that best suits his or her needs. However, if you must resize the width of the task pane, you could use the following code to achieve this task.
You cannot directly reposition the ActionsPane because it is embedded in the task pane. However, you can programmatically move the task pane by setting the Position property of the CommandBar that represents the task pane.
Programmatically repositioning the task pane is generally not recommended because the user should be able to choose the task pane position on the screen that best suits his or her needs. However, if you must move the task pane to a particular position, you could use the following code to achieve this task.
End users can manually reposition the task pane at any time. There is no way to ensure that the task pane will remain docked at the position you indicate programmatically. However, you can check for orientation changes and ensure that the controls on the actions pane are stacked in the correct direction. For more information, see How to: Manage Control Layout on Actions Panes.
If the task pane is not docked, you can set the Top and Left properties of the CommandBar that represents the task pane. The following code moves an undocked task pane to the upper-left corner of the document.