Create a COM Add-in for Microsoft Project
Developing and distributing a COM add-in is one way to provide users with a custom solution for Microsoft® Project 2000. An add-in extends Microsoft 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 Component Object Model (COM) add-in for Microsoft Project 2000. The template allows you to add features to customize the add-in for your needs.
Code CenterThe Visual Basic template files are available from the Microsoft Download Center.
Using the Visual Basic 6.0 Template Files
The Code Center includes a set of template files you can use for creating a COM add-in for Microsoft Project in Visual Basic. To use the template, download the self-extracting file from the Code Center, which installs the following files:
The source code in the Connect.dsr designer module is heavily commented to help you add toolbars and custom menus, as well as locate string constants and variables. The Visual Basic form file, frmProjectAddIn.frm, has been set up with OK and Cancel buttons; however, the form can be extended as needed. 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 as needed.
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").
Installing a Template in Visual Basic 6.0
If you intend to create multiple add-ins for Microsoft 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 Microsoft 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 the MyProjectAddIn.vbp file and saving the project under a different name.
To install a new template in Visual Basic:
- Download the self-extracting zip file from the Microsoft Download Center.
- Copy the files MyProjectAddIn.vbp, Connect.dsr, frmProjectAddIn.frm, and MyProjectAddIn.res to the template directory for Visual Basic 6.0.
The default template directory 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 have installed the template files in the proper directory, you can select the Microsoft Project add-in template from the list of available projects.
To select the add-in template:
- On the File Menu, click New Project.
- 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 directory 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 none, one, or all 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. You can create and edit a resource file by using the Resource Editor Add-in in Visual Basic 6.0.
To install and use the Visual Basic Resource Editor add-in:
- From the Add-Ins menu, click Add-In Manager.
- In the Available Add-Ins list, click VB 6 Resource Editor.
- Under Load Behavior, select the check boxes for the behaviors you want to enable for the Resource Editor add-in.
- On the Tools menu, click Resource Editor.
- In the VB Resource Editor dialog box, use the menu buttons to add cursors, icons, bitmaps, or custom resources, or to edit string tables.
- Click Save.
- 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
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 Microsoft Project to test and debug it by using any of the Visual Basic debugging tools.
To debug a COM add-in:
- Open the add-in project in Visual Basic.
- In the Project Explorer, double-click the Connect.dsr designer module.
- On the View menu, click Code.
- Place a break point in the show function.
- On the Run menu, click Start With Full Compile.
This command compiles your project, alerting you of any compilation errors, and puts your project into run mode.
- Open Microsoft 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.
The following articles provide more information on creating COM add-ins for Office applications, and the information can be applied to creating a COM add-in for Microsoft Project.