Export (0) Print
Expand All

How to: Add an Actions Pane to Excel Workbooks

To add an actions pane to a Microsoft Office Excel workbook, first create a Windows Forms user control. Then, add the user control to the Controls property of the ThisWorkbook.ActionsPane field in your project.

Applies to: The information in this topic applies to document-level projects for Excel 2007 and Excel 2010. For more information, see Features Available by Office Application and Project Type.

NoteNote

Your computer might show different names or locations for some of the Visual Studio user interface elements in the following instructions. The Visual Studio edition that you have and the settings that you use determine these elements. For more information, see Working with Settings.

link to video For a related video demonstration, see How Do I: Use WPF Controls Inside an Excel Actions Pane?.

The following procedure shows how to create a user control in an Excel project. It also adds a button to the user control that writes text to a worksheet cell when it is clicked.

To create the user control

  1. Open your Excel workbook or template project in Visual Studio.

  2. On the Project menu, click Add New Item.

  3. In the Add New Item dialog box, select Actions Pane Control, name it HelloControl, and click Add.

    NoteNote

    You can alternatively add a User Control item to your project. The classes generated by the Actions Pane Control and User Control items are functionally equivalent.

  4. From the Windows Forms tab of the Toolbox, drag a Button control to the control.

    NoteNote

    If the control is not visible in the designer, double click HelloControl in Solution Explorer.

  5. Add the following code to the Click event handler of the button.

    
    private void button1_Click(object sender, System.EventArgs e)
    {
        Globals.Sheet1.Range["A1", System.Type.Missing].Value2 = "Hello World!";
    }
    
    
    
  6. In C#, you must create an event handler for the Button. You can place this code in the HelloControl constructor. For more information about creating event handlers, see How to: Create Event Handlers in Office Projects.

    
    public HelloControl()
    {
        InitializeComponent();
        this.button1.Click += new System.EventHandler(this.button1_Click);
    }
    
    
    

To show the actions pane, add the user control to the Controls property of the ThisWorkbook.ActionsPane field.

To add the user control to the actions pane

  1. Add the following code to the ThisWorkbook class as a class-level declaration (do not add this code to a method).

    
    private HelloControl hello = new HelloControl();
    
    
    
  2. Add the following code to the ThisWorkbook_Startup event handler of the ThisWorkbook class.

    
    this.ActionsPane.Controls.Add(hello);
    
    
    

Community Additions

ADD
Show:
© 2014 Microsoft