May 23, 2009

How to create PowerPoint add in with C#.Net

Add-in helps us by automating our daily routine work. So let us make simple one.
Create a project of type Shared add-in Visual Studio as shown in a below snapshot.

Step 1

Click Ok. After clicking a wizard will appear as shown below.

step 2

Click next to a language of you choice for development of Add-in. You can select any of the available languages but here, I have selected C# as my preferred language for development of Add-in.

step 3

As we are creating add-in for PowerPoint our scope will be only PowerPoint. So Check the Microsoft PowerPoint option only leaving all other unchecked as shown below.

step 4

Give a name and description for add-in. We will call our add-in as "Solo Addin" and add a sample description as "Sample Solo Addin"

step 5

Choose options for your add-in loading. We will check first option to suggest that PowerPoint should load our add-in when it loads. Second option suggests that the add-in will be available to all users on a machine. You can change this option in deployment deploying.

step 6

Next screen shows summary of all the steps we have gone through.

step 7

Click on Finish button and that's all. This will create all the necessary framework and code to get started with.

We have main Connect class which will be a mediator between the code we are going to write and PowerPoint. Connect Class will have a unique GUID for an add-in to differentiate between add-ins or to uniquely identify an add-in. You Connect class GUID line will look like the below one.

[GuidAttribute("85D322E5-B30F-48EB-83A4-CB3CD133010F"), ProgId("Solo.Connect")] 
Connect class has main Five event
  • OnConnection - fires immediately after Connect Constructor
  • OnDisconnection - fires after add-in shutdown
  • OnAddInsUpdate - fires when add-in updates
  • OnStartupComplete - fires when loading is complete. We will initialize the add-in here.
  • OnBeginShutdown - fires when host application begins to shutdown. We will do cleanup things here.

So for now we will just show a MessageBox to know that we are on track. Add reference of System.Windows.Forms dll to the project to get MessageBox work. Add using statement to your Connect class

using System.Windows.Forms;

Show MessageBox on OnStartupComplete event.
/// <summary>
///      Implements the OnStartupComplete method of the IDTExtensibility2 interface.
///      Receives notification that the host application has completed loading.
/// </summary>
/// <param term='custom'>
///      Array of parameters that are host application specific.
/// </param>
/// <seealso class='IDTExtensibility2' />
public void OnStartupComplete(ref System.Array custom)
     MessageBox.Show("Hello World!");
Build add-in project, Open PowerPoint, and you should get an MessageBox saying "Hello World!"

This post show how to go get started with PowerPoint add-in development.

1 comment:

  1. Hi
    Nice post!
    By visiting your blog I learned How to create powerpoint addin with C#.Net
    Thank you