Exercise 2: Building a Word 2010 Add-in

In this exercise you will use the built in ribbon customization functionality to build your own ribbon.

Task 1 – Create a new Word 2010 Addin

In this task, you will create a simple Word 2010 add-in that displays a message box when it is loaded.

  1. Open Visual Studio 2010 and create a new Word 2010 Add-in
    1. Start Visual Studio 2010 by clicking the Visual Studio icon on the taskbar
    2. Click the File -> New -> Project menu item
    3. In the New Project dialog, select Visual C#\Visual Basic -> Office -> 2010 template category
    4. Select the Word 2010 Add-in project template
    5. Enter a Name of Word2010AddIn and set the location to %Office2010DeveloperTrainingKitPath%\Labs\GettingStarted\Source\[language]\Starter
    6. Uncheck the Create directory for solution check box
    7. Click OK to create the new project

      Figure 4(a)

      Figure 4(b)

      New Word 2010 Add-in

  2. Add the code to display a message box when the add-in loads
    1. In the Solution Explorer double click ThisAddIn.cs(ThisAddIn.vb in case of VB)
    2. Add the following using statements to the file

      C#

      using System.Windows.Forms;

      Visual Basic

      Imports System.Windows.Forms

    3. Locate the ThisAddIn_Startup method and add the code to display a message box

      C#

      private void ThisAddIn_Startup(object sender, System.EventArgs e)
      FakePre-113fc445da6e4afcb120f4a683ceebe3-04b9bbc930124a3c9e95eac7dc257b2c MessageBox.Show("Add-in is starting up");FakePre-f0c4311b5f3a4056a60df40264b2530e-da2061931e6a4de1b3e96c2c797f61d9

      Visual Basic

      Private Sub ThisAddIn_Startup(ByVal sender As Object, ByVal e As System.EventArgs)
      MessageBox.Show("Add-in is starting up")FakePre-c8d0ad8d76ba4b37b3c48e2ecf266228-e41a0265a6344fcf8009e730c2e34390

  3. Set a breakpoint and start the debugger
    1. Locate the ThisAddIn_Startup method in the ThisAddIn class
    2. Place a breakpoint on the first line of the function.

      Figure 5(a)

      Figure 5(b)

      Setting breakpoint

    3. Start the debugger by pressing F5
    4. Wait for the add-in start and stop on the breakpoint

      Figure 6(a)

      Figure 6(b)

      Breakpoint hit

    5. Continue running by pressing F5 and verify the message box is displayed

      Figure 7

      Add-in startup message box

      Note:
      Office Add-ins support debugging directly from Visual Studio 2010

  4. When you are done cleanup and remove the add-in
    1. Close Word 2010
    2. In the Solution Explorer, right click Word2010AddIn and click Clean
      Note:
      The Clean option deletes a temporary add-in registration that allows Visual Studio to quickly register the add-in for development purposes