Office add-in in Delphi: add-in
custom ribbons, tabs, menu items, buttons

Add-in Express™
for Microsoft® Office and Delphi® VCL

Create Office COM add-ins in Delphi

Add-in Express for Office and Delphi VCL is completely based on the Rapid Application Development (RAD) paradigm which makes the development of COM add-ins for Microsoft Office applications much quicker and easier. Office add-in developers will definitely appreciate the following features:

  • Visual designers, special components and project templates allow you to create sophisticated Office add-ins without coding their GUI.
  • Ability to create both application-specific add-ins, e.g. Outlook or Excel plug-ins, and shared plugins that work on all applications: Outlook, Excel, Word, PowerPoint, Visio, Project, MapPoint, Publisher, Access, FrontPage and InfoPath.
  • Special components for customizing the Office Ribbon UI (Ribbon button and all Ribbon controls) enable you to add new or customize existing tabs for the Office Ribbon UI, build the Quick Access Toolbar and the File Tab (BackstageView). More about Office Ribbon UI designer.
  • Add-in Express directly integrates its projects with the Office Automation Server components and allows you to access add-in host application objects and handle their events.

The sample below describes creating a COM add-in for Microsoft Excel and Microsoft Word. Another sample COM add-in for Office is available in the Developer's Guide.

1. Create a new COM add-in project with Add-in Express wizard

In the Delphi IDE, close all opened projects, select the "File|New|Other:" item on the main menu, and run the "Add-in Express COM Add-in" wizard on the "Add-in Express VCL" tab of the "New Item" dialog box.

Creating a COM add-in project with the Add-in Express wizard

In the wizard windows, you enter the name and the destination folder for the add-in project, select either user or admin privileges for the add-in installation. The wizard then generates a new project and opens it in the Delphi IDE.

The add-in module

2. Customizing your Office add-in

The project includes the Add-in Module (MyAddin1_IMPL.pas on the screenshot above), which is the core part of Add-in Express based add-ins. The add-in module supports all Office versions from 2000 to 2021 32-bit and 64-bit and allows you to concentrate all code of the add-in in one place.

Add-in module programmability:

Add-in name, description, and load behavior and supported Office applications
If the add-in is per user or per machine (for all users on the PC)
Host application interface, e.g. ExcelApp and WordApp
When the add-in completes start-up routines or is required to shut down
Before the Ribbon XML markup is created and loaded, after the Ribbon XML markup is loaded
Find CommandBar and Ribbon controls
Activate Ribbon tab

3. Adding a custom tab to the Office Ribbon

Add an instance of the Ribbon Tab component (TadxRibbonTab) to the module and populate the tab with controls using its visual designer. You can add any control to your custom ribbon tab.

The Ribbon tab visual designer

To add a built-in control onto a custom tab or to add a custom Ribbon group onto a built-in Ribbon tab, you need to know the ID of the built-in control or tab.

The Ribbon Tab component creates and verifies the Office Ribbon XML markup automatically.

Ribbon controls programmability:

Caption, key tip, and position in Ribbon
Supported ribbons and context (say, Pivot Table in Excel or Table in Word)
Visible and Enabled (Boolean)
Actual events depend on actual control types used. E.g. button, checkbox, and splitbutton provide OnClick, edit box provides OnChange, etc.

4. Customizing Office Ribbon UI

You can use the following Ribbon components:

Backstage View Allows customizing Office File Tab, aka BackstageView in Office 2010 - 2021.
Ribbon Office Menu Allows customizing Office 2007 menu, aka Office Button.
Ribbon Excel, Outlook, Word Use this component to customize the Quick Access Toolbar in Office 2007 - 2021.
Ribbon Command Use it to intercept invoking built-in Ribbon commands by the user.
Ribbon Context Menu Enables customizing built-in context menus in Office 2010 - 2021.
CommandBar Context Menu Allows customizing Office 2007 - 2021 context menus using the old-fashioned command bar based approach.

For instance, you can add a BackStage View component (TadxBackStageView) to the module and use its designer to customize the File tab. More about Ribbon components.

BackStage View

5. Custom panes in Office 2000 - 2021

Add-in Express supports two pane types that work in different Office versions and provide different functionality:

  • Native Office panes, called Custom Task Panes, available in Office 2007 - 2021
  • Add-in Express panes called Advanced Task Panes available in Office 2000 - 2021

Advanced task panes give you a well-considered object model and flexibility. Their context-sensitivity and visualization options cover a wide range of end-user requests.

The technology is based on three entities:

  • Advanced Task Pane descending from TForm
  • Task panes manager that orchestrates the whole process
  • An item in the manager's Items collection, which specifies where and how to show a particular pane

Advanced task pane settings

Advanced task pane programmability:

Show or hide the task pane
The position where to show your pane
If the form sizing is controlled by the user or by the developer
Default state and possible task pane states: normal, minimized, hidden, overlapping
Drag-n-drop: available drop positions
Before your task pane becomes visible

More about Advanced Office task panes.

6. Adding an Office 2000 - 2003 command bar

To add a custom toolbar to your add-in, drop a TadxCommandBar component onto the add-in module. Then specify the command bar properties and populate it with controls using the designer of the TadxCommandBar component.

Command bar designer

Available control types follow below:

  • CommandBar Button
  • CommandBar Edit
  • CommandBar ComboBox
  • CommandBar DropDownList
  • CommandBar Control

Commandbar programmability:

Commandbar name, position, protection and supported Office applications
Temporary or permanent
Collection of command bar controls
Whether the command bar will show up in the Office Ribbon interface

Commandbar controls programmability:

Caption, icon, showing the caption and the icon in different styles
Temporary or permanent
Position, Visible and Enabled
Collection of command bar controls (only popup)
OnClick (button), OnChange (edit, combo, dropdown)

7. Customizing the CommandBar UI of Office 2000 - 2003

Add-in Express provides these components for customizing the toolbar subsystem of Office 2000, XP and 2003 applications:

CommandBar component CommandBar Supports creating custom and customizing built-in toolbars in Office 2000 - 2003. Pay attention, there are Outlook-specific versions of this component!
Office Menu component Main Menu It allows customizing main menus in Office 2003 - 2000 applications. Outlook-specific versions of this component are also provided.
Context Office Menu component Context Menu Allows customizing context menus in Office 2000 - 2003 using the old-fashioned command bar based approach.

For instance, you can customize an Office context menu in the following way:

Office context menu designer

Find more about Command bar components.

9. Handling user actions and application events

You can use the Add-in Express components to intercept and cancel pressing a keyboard shortcut or keyboard combination, clicking a built-in command bar or Ribbon command as well as to handle events of the host application. Add-in Express also provides host-specific components to intercept application-level events in a handy, version-independent way.

The Add-in Express components to intercept Excel events

The application-level event components are provided for all supported Office 2021 - 2000 applications including Outlook, Excel, Word, PowerPoint, Visio, Project and others.

8. Running the add-in

Save the project, compile it, close all the applications that you have selected as add-in host applications, and register the add-in via "Run|Register ActiveX Server". Run one of the selected host applications, find your Ribbon tab or toolbar and click on the button. The screenshot bellow shows a custom ribbon button in Excel:

A custom ribbon button in Excel