Create a COM Add-in for Microsoft Office Project 2003

Summary

Developing and distributing a Component Object Model (COM) add-in is one way to provide users with a custom solution for Microsoft Office Project 2003. An add-in extends Project by adding functionality that is not in the core product. For example, an add-in might add new menu commands or toolbar buttons that display custom forms to add new features.

This article describes how you can use a Microsoft Visual Basic designer template to quickly create a COM add-in for Microsoft Office Project 2003. The template allows you to add features to customize the add-in for your needs. If you are trying to create a managed COM add-in using Microsoft Visual Studio .NET, see the MSDN article Creating Managed Add-Ins for Project.

Download    The COM Add-in Template for Microsoft Office Project 2003 (pj11COMAddIn.exe) file is available from the Microsoft Download Center.

Note  This executable (pj11COMAddIn.exe) is a new version for Microsoft Office Project 2003. Similar executables exist in the SDKs for Microsoft Project 2000 and 2002.

Using the Visual Basic 6.0 Template Files

The MSDN Code Center includes a set of template files you can use to create a COM add-in for Project in Visual Basic. The Visual Basic COM add-in designer template for Project is based on the designer template for Office applications, with some customizations that are relevant to Project. To use the template, run the self-extracting file pj11COMAddIn.exe from the download, which installs the following files:

  • MyProjectAddIn.vbp
  • Connect.dsr
  • frmProjectAddIn.frm
  • MyProjectAddIn.res

Note  The Visual Basic template files for Microsoft Office Project 2003 have been updated since Microsoft Project 2002, with additional comments and references in some of the files. If you are planning to build a COM add-in for Microsoft Office Project 2003, you should download the new files.

You can start a new project by opening the MyProjectAddIn.vbp project file in Visual Basic, or you can install the files as a template for multiple uses (see the following section, Installing a Template in Visual Basic 6.0).

The main advantage of the designer template is that it provides an easy way for you to create a COM add-in for Project 2003. You can start with the provided designer template, and immediately have a functioning COM add-in framework to work with.

The source code in the Connect.dsr designer module is heavily commented to help you add toolbars and custom menus, as well as to locate string constants and variables. The Visual Basic form file, frmProjectAddIn.frm, has OK and Cancel buttons by default; however, the form can be extended.

The MyProjectAddIn project also contains a resource file, MyProjectAddIn.res, which contains a sample bitmap. A resource file can store additional bitmaps, text strings, or other data.

Installing a Template in Visual Basic 6.0

If you intend to create multiple add-ins for Project, you can create your own template from these files to use in Visual Basic. After you install the template files, you can create a new COM add-in for Project by using the New Project dialog box in Visual Basic. If you do not wish to install a template from these files, you can still customize the Code Center files for a single COM add-in by opening and working with the MyProjectAddIn.vbp file.

To install a new template in Visual Basic:

  1. Download and install the self-extracting file pj11COMAddIn.exe from the Microsoft Download Center.

  2. Copy the files MyProjectAddIn.vbp, Connect.dsr, frmProjectAddIn.frm, and MyProjectAddIn.res to the template folder for Visual Basic 6.0.

    The default template folder for Visual Basic 6.0 is C:\Program Files\Microsoft Visual Studio\VB98\Template\Projects.

Starting a New Project from a Template in Visual Basic

After you install the template files in the template folder, you can select the Project add-in template from the list of available projects.

To select the add-in template:

  1. On the File Menu, click New Project.
  2. In the New Project dialog box, click MyProjectAddIn.

The designer template organizes the project files into three folders: Forms, Designers, and Related Documents. If the folder structure is not visible, click Toggle Folders in the Project Explorer pane.

The source code of the add-in designer template, Connect.dsr, contains comments about required or suggested alterations. For example, the template includes a function for adding an entry to a menu item, a function for adding a new toolbar, and a function for adding a new toolbar item. You may want to use any number of these options, depending on the functionality goal of the add-in you are creating.

The MyProjectAddIn template also includes a resource file, which allows you to collect all of the version-specific text and bitmaps for an application in one place. This can include icons, screen text, and other material that may change between localized versions or between revisions or specific configurations.

To use the resource file included with this download, double-click MyProjectAddIn.res to edit it in the Visual Basic Resource Editor. If the Visual Basic Resource Editor is not installed, or if you want to create a new resource file for your add-in, follow these instructions to install the Resource Editor add-in in Visual Basic 6.0.

To install and use the Visual Basic Resource Editor add-in:

  1. From the Add-Ins menu, click Add-In Manager.

  2. In the Available Add-Ins list, click VB 6 Resource Editor.

  3. Under Load Behavior, select the check boxes for the behaviors you want to enable for the Resource Editor add-in. The options are Loaded (meaning that the selected add-in is currently loaded into the IDE and it is available for use) and Load on Startup.

  4. On the Tools menu, click Resource Editor.

  5. In the VB Resource Editor dialog box, use the menu buttons to add cursors, icons, bitmaps, or custom resources, or to edit string tables.

  6. Click Save.

  7. In the Save Resource File As dialog box, type a name for the file, and then click Save.

    Visual Basic creates a folder called Related Documents, which contains your resource files.

    Note  The resource file is not saved with the designer module and the Visual Basic form file when you save the project template files on your local computer. When starting a new project from the designer template, you should use the resource editor to save the resource file with the rest of the project.

Debugging a COM Add-in

When you're developing a COM add-in in Visual Basic, you can debug the add-in by putting the project into run mode. With the project in run mode, you can load and use the COM add-in from within Project to test and debug it by using any of the Visual Basic debugging tools.

To debug a COM add-in:

  1. Open the add-in project in Visual Basic.

  2. In the Project Explorer, double-click the Connect.dsr designer module.

  3. On the View menu, click Code.

  4. Place a break point in the show function.

    Note  To avoid inconsistent behavior in the way Visual Basic debugs COM add-ins, it is necessary to insert at least one break point in the show function before running the COM add-in in Project.

  5. On the Run menu, click Start With Full Compile.

  6. This command compiles your project, alerts you of any compilation errors, and puts your project into run mode.

  7. Open Project.

    When the add-in loads, the OnConnection event occurs. You can now enter break mode in the add-in project in Visual Basic 6.0, and debug the code.

For more information, see Debugging a COM Add-in.

Additional Information

There are many articles available on MSDN that provide useful information about creating Microsoft Office COM add-ins. Most of the following articles also apply to creating a Project 2003 COM add-in.

If you are trying to create a managed COM add-in using Visual Studio .NET, refer to the following topic: Creating Managed Add-ins for Project.

Building COM Add-ins for Office Applications

Add-ins, Templates, Wizards, and Libraries

Deploying COM Add-ins

COM Add-ins Part I: Introducing an Office 2000 Solution for the Entire (Office) Family

Developing COM Add-Ins for Microsoft Office 2000

If you are trying to create a COM add-in for Microsoft Project 2002, see the following MSDN article:

Create a COM Add-in for Microsoft Project 2002

In addition, the following Microsoft Knowledge Base Article from Microsoft Product Support Services provides useful information about how to build COM add-ins for Office 2000. The information can still be applied to Microsoft Office 2003 and Project 2003.

HOWTO: Build an Office 2000 COM Add-In in Visual Basic