Designers for COM add-ins, RTD servers, smart tags
Excel Automation add-ins, XLL in C#, VB.NET, C++
Add-in Express™ Add-in Express .NET designersThere are several Add-in Express designer types responsible for common tasks in automating Microsoft Office 2010 - 2000 in .NET (C#, VB.NET, C++). Add-in Express installs a number of items to the New Project dialog as well as to the Add New Item dialog in order to allow creating the following customization types:
New Project dialogAdd-in Express adds several project templates to the Extensibility folder of the New Project dialog in Visual Studio. To see the dialog, choose File | New | Project… in the main menu. Whichever Add-in Express project template you choose, it starts a project wizard that allows selecting a programming language for your project, interop assemblies to use as well as other options. The project wizard creates a new solution containing an appropriate Add-in Express project. Each Add-in Express project contains an appropriate designer class also called "module": add-in module, XLL module, RTD server module, etc. Project-specific modules are the core components of Add-in Express. You can add any components onto the modules. Add-in Express provides a number of components that simplify and speed up the development of Office extensions, see Add-in Express components. Add New Item dialogAdd-in Express installs the following items to the Add New Item dialog (right-click your project item in Solution Explorer and choose Add New Item in the context menu).
COM add-insCOM add-ins have been around since Office 2000 when Microsoft allowed Office applications to extend their features with COM DLLs supporting the IDTExtensibility2 interface (it is a COM interface, of course). Since then thousands of developers have racked their brains over this interface and the Office object model that provided COM objects representing command bars, command bar controls, etc. These were the sources of Add-in Express.Why COM add-ins?COM add-ins is the only way to provide new or re-use built-in UI elements such as command bar controls and Ribbon controls. Say, a COM add-in can show a command bar or Ribbon button to process selected Outlook e-mails, Excel cells, or paragraphs in a Word document and perform some actions on the selected objects. A COM add-in supporting Outlook, Excel, Word or PowerPoint can show custom task panes in Office 2007 and higher and Add-in Express panes in Office 2000-2010, see Task panes. In a COM add-in targeting Outlook, you can add custom option pages to the Tools | Options and Folder Properties dialogs (see Step 14. Adding property pages to the Folder Properties dialog). A COM add-in also handles events and calls properties and methods provided by the object model of the host application. For instance, a COM add-in can modify an e-mail when it is being sent; it can cancel saving an Excel workbook; or, it can check if a Word document meets some conditions. Per-user and per-machine COM add-insA COM add-in can be registered either for the current user (the user running the installer) or for all users on the machine. That's why the corresponding module type, ADXAddinModule, provides the RegisterForAllUsers property. Registering for all users means writing to HKLM and that means the user registering a per-machine add-in must have administrative permissions. Accordingly, RegisterForAllUsers = Flase means writing to HKCU (=for the current user). See also Registry keys. An add-in deployed via ClickOnce can be registered with HKCU only. See also ClickOnce deployment. A standard user may turn a per-user add-in off and on in the COM Add-ins dialog. You use that dialog as well as the {host application} | Options | Add-ins dialog in Office 2007-2010 to find if your add-in is active. Creating a COM Add-in projectTo create a COM add-in, choose the Add-in Express COM Add-in project template in the New Project dialog. The core of the project is the add-in module, of the ADXAddinModule type. The add-in module represents a COM add-in in any Office application. To add another add-in to your assembly, add another add-in module to your project (see Add New Item dialog). For the add-in, you specify its name, host application(s) and load behavior. The typical value for the LoadBehavior property is Connected & LoadAtStartup. That value is written to the registry when you register the add-in. For Outlook add-ins, you also specify pages for the Tools | Options and Folder Properties dialogs (see Outlook Property page). See also what Add-in Express components you add onto add-in modules. Pay attention to the AddinExpress.MSO.ADXAddinModule.CurrentInstance method (it's static in C#, Shared in VB.NET); it allows accessing public properties and method outside of the module. Use the AddinStartupComplete and AddinBeginShutdown events to handle add-in startup and shutdown.Here you can find two sample add-in projects: sample Excel add-in project and sample Outlook add-in project. What's next?You need to study the following areas before implementing the business logic of your add-in:
RTD serversRTD Server is a technology introduced in Excel 2002 (XP). An RTD server is used to provide the end user with a flow of changing data such as stock quotes, currency exchange rates etc. If an RTD server is mentioned in a formula (placed on an Excel worksheet), Excel loads the RTD server and waits for new data from it. When data arrive, Excel seeks for a proper moment and updates the formula with new data. RTD server terminology:
Per-user and per-machine RTD ServersAn RTD Server can be registered either for the current user (the user running the installer) or for all users on the machine. That's why the corresponding module type, ADXRTDServerModule, provides the RegisterForAllUsers property. Registering for all users means writing to HKLM and that means the user registering a per-machine RTD server must have administrative permissions. Accordingly, RegisterForAllUsers = Flase means writing to HKCU (=for the current user). Creating an RTD serverTo create an RTD server, choose Add-in Express RTD Server in the Add New Item dialog. The project designer type is ADXRtdServerModule (RTD server module). The only Add-in Express component allowed for this designer is RTD Topic. The module provides the Interval property that indicates the time interval between updates (in milliseconds). You refer to an existing RTD Server using the RTD worksheet function in Excel: =RTD(ProgID, Server, String1, String2, ... String28) The ProgID parameter is a required string value representing the programmatic ID (or ProgID - see What is ProgID) of the RTD server. See attributes of the RTDServerModule class for the ProgID of your RTD Server. The current version of Add-in Express requires the Server parameter to be an empty string. Use two quotation marks (""). The String1 through String28 parameters allow specifying topics of the RTD server. Only the String1 parameter is required; the String2 through String28 parameters are optional. The actual values for the String1 through String28 parameters depend on the requirements of the real-time data server. What's next?Please see RTD Topic and a sample RTD server project. Also, find useful information in How to get actual parameters of the RTD function when using an asterisk in the string## properties of a topic? and Inserting the RTD function in a user-friendly way. Smart tagsOffice XP bestowed Smart Tags upon us in Word and Excel. Office 2003 added PowerPoint to the list of smart tag host applications. This technology provides Office users with more interactivity for the content of their Office documents. A smart tag is an element of text in an Office document having custom actions associated with it. Smart tags allow recognizing such text using either a dictionary-based or a custom-processing approach. An example of such text might be an e-mail address you type into a Word document or an Excel workbook. When smart tag recognizes the e-mail address, it allows the user to choose one of the actions associated with the text. For e-mail addresses, possible actions are to look up additional contact information or send a new e-mail message to that contact. Note. Smart tags are deprecated in Excel 2010 and Word 2010. Although you can still use the related APIs in projects for Excel 2010 and Word 2010, these applications do not automatically recognize terms, and recognized terms are no longer underlined. Users must trigger recognition and view custom actions associated with text by right-clicking the text and clicking the Additional Actions on the context menu. Please see Changes in Word 2010 and Changes in Excel 2010. ADXSmartTagModule lies at the base of the Add-in Express Smart Tags. It represents a set or a library of smart tag recognizers in Excel, Word, and PowerPoint. The only Add-in Express component you add to the designer is Smart Tag. To create a smart tag, choose Add-in Express Smart Tag in the New Project dialog. ADXSmartTagModule, smart tag module, constitutes the base of Add-in Express smart tags. It represents a set or a library of smart tag recognizers in Excel, Word, and PowerPoint. The only Add-in Express component you add to the designer is Smart Tag. See how to build smart tags for Word and Excel. Excel UDFsExcel UDFs are used to build custom functions in Excel for the end user to use them in formulas. This definition underlines the main restriction of an Excel UDF: it must return a result that can be used in a formula - not an object of any given type but a number, a string, or an error value (Booleans and dates are essentially numbers). When used in an array formula, the UDF must return a properly dimensioned array of values of the types above. There are two Excel UDF types: Excel Automation add-ins and Excel XLL add-ins. They differ in several ways: see What Excel UDF type to choose? Excel Automation add-insExcel 2002 brought in Automation Add-ins - a technology that allows writing user-defined functions for use in Excel formulas. Add-in Express .NET provides you with a specialized module, COM Excel Add-in Module, that reduces this task to just writing one ore more user-defined functions. A typical function accepts one or more Excel ranges and/or other parameters. Excel shows the resulting value of the function in the cell where the user calls the function. To create an Excel Automation add-in, create a COM add-in project (see COM Add-ins) and choose COM Excel Add-in Module in COM Add-in in the Add New Item dialog. This adds an ADXExcelAddinModule (Excel add-in module) to the COM add-in project. The module represents an Excel Automation add-in. It does not provide any properties. See how to create Excel Automation Add-in step-by-step. Excel XLL add-insAn XLL is a DLL written in such a way that Excel can open it directly. Like Excel Automation add-ins, XLL add-ins are mostly used to create user-defined functions, however they do it much faster. This technology was introduced in Excel 4.0; Wikipedia states that this happened in 1992! Since then, XLL interfaces have been available for C and C++ developers only. Now, Add-in Express hides XLL complexities for .NET developers. To create an XLL add-in, choose Add-in Express XLL Add-in in the New Project dialog. The project designer class is ADXXLLModule (XLL add-in module). The module contains a special class, XLLContainer, where you add your public static (in VB, Public Shared) functions. Just adding a function is enough for a quick start. Using the module's designer, you are able to specify all other function-related stuff: description, help reference, category, descriptions of the function's parameters, etc. In addition, you can instruct Excel to call your function whenever recalculation is required (IsVolatile property). Another option is specifying the AcceptAsArray property that allows accepting an Excel range passed to your UDF as a 2D array of values or as a reference to an object of the ADXExcelRef type. See a sample XLL add-in project. What Excel UDF type to choose?Excel Automation add-ins are supported starting from Excel 2002; Excel XLL add-ins work in Excel 2000 and higher. Automation add-ins are suitable if your UDF deals a lot with the Excel object model; XLL add-ins are faster in financial and mathematical calculations. Note however that native code XLL add-ins work faster than managed UDFs. Information below applies to the Add-in Express implementation of Excel Automation add-ins and XLL Add-ins.
Excel workbooksSometimes you need to automate a given Excel workbook (template). You can do it with ADXExcelSheetModule that represents one worksheet of the workbook. The Document property allows creating and browsing for the workbook. If you choose creating a new workbook, the dialog appears where you specify the name and location of the workbook as well as the Property Name and Property Value textboxes. Add-in Express adds this property to the list of custom properties of the workbook and uses the name and value of the property in order to recognize the workbook. Accordingly, you specify the PropertyId and PropertyValue properties of the module. The module provides a full set of events available for an Excel workbook. For the Add-in Express components available for the module see the following chapters: Command Bars: toolbars, menus, and context menus and Application-level events. More about customizing Excel workbooks. Note. There is a sample project for this module type. It is called TimeSheet. Together with other sample projects, it can be downloaded here. Word documentsTo automate a given Word document, you use the ADXWordDocumentModule. The module allows creating and browsing for the document. If you choose creating a new document, the dialog appears where you specify the name and location of the document as well as the Property Name and Property Value textboxes. Add-in Express adds this property to the list of custom properties of the document and uses the name and value of the property in order to recognize the document. Accordingly, you specify the PropertyId and PropertyValue properties of the module. The module provides a full set of events available for Word document. Note. There is a sample add-in for Word for this module type. It is called WordFax. Together with other sample projects, you can download it from the HowTo section. |