Share via


Targeting User Interface Solutions to the 2007 and 2010 Releases of Microsoft Office

**Summary:**Microsoft Office 2010 expands on the features that were introduced in the 2007 release of Microsoft Office. See how you can create solutions that target one version of Microsoft Office or both versions. (3 Printed Pages)

Applies to: Excel 2010 | Office 2007 | Office 2010 | Open XML | PowerPoint 2010 | SharePoint Server 2010 | VBA | Word 2010

Published:   November 2009

Provided by:   Mirko Mandic, Microsoft Corporation

Contents

  • Authoring Solutions for the 2007 Office System and Microsoft Office 2010

  • Creating a Document-Based Solution

  • Creating a COM Add-In Solution

  • Conclusion

Authoring Solutions for the 2007 Office System and Microsoft Office 2010

Microsoft Office 2010 evolves the Microsoft Office Fluent user interface (UI) extensibility model by expanding the platform introduced in the 2007 release with new features and also, by introducing support for customizing the new Backstage view.

This article describes how to create UI extensibility solutions that are compatible with the 2007 release of Microsoft Office, Microsoft Office 2010, or both.

The new UI extensibility features are described in detail in the article Introduction to the Office 2010 Backstage View for Developers.

Creating a Document-Based Solution

Just as in the 2007 release, you can customize the UI in Office 2010 for a specific document. And, as in the 2007 release, this is achieved by adding an XML file with your custom UI definition to the Office Open XML format file.

  • If your solution targets the 2007 release (or if it targets Office 2010, but you do not want to use the new UI extensibility features introduced in Office 2010), you can rely on the UI extensibility approach introduced in the 2007 release—the XML file with your UI customizations should use the namespace for the 2007 Office system and the relationships (.rels) file should contain a relationship targeting the 2007 Office system.

    This also means that if you wrote a solution in Office 2007, it works in Office 2010 without any required modifications.

    The namespace for the 2007 release is https://schemas.microsoft.com/office/2006/01/customui. The corresponding relationship namespace is https://schemas.microsoft.com/office/2006/relationships/ui/extensibility.

  • If your solution targets Office 2010, you need to ensure that you use the appropriate namespace and the corresponding relationship in the Office Open XML format file. The Office 2010 namespace is https://schemas.microsoft.com/office/2009/07/customui. The corresponding relationship namespace is https://schemas.microsoft.com/office/2007/relationships/ui/extensibility.

  • If your solution targets both the 2007 release and the 2010 release (and you want your Office 2010 version to use the new UI extensibility features, which are not supported in the 2007 release), you need to have two custom UI XML files in the Office Open XML file, each extending the appropriate version of Office. You also need to ensure that the relationships file contains appropriate relationship entries for both of the files.

Table 1. How the 2007 and 2010 release of Office use custom UI XML file(s)

XML Files

2007 Office system

Office 2010

XML file for use with the 2007 Office system

XML file is used

XML file is used

XML file for use with Office 2010

XML file is ignored

XML file is used

XML files for both the 2007 Office system and Office 2010

XML file for the 2007 release is used and Office 2010 XML file is ignored

Office 2010 XML file is used and the XML file for the 2007 release is ignored

At the document level, the process for customizing the Office Fluent UI involves the following steps:

  1. Replace the extension in your macro-enabled file name (.docm, .xlsm, etc.) with a .zip extension.

  2. Open the Zip package and add the XML file that defines your custom UI to the package.

    In addition to ensuring that your markup uses tags appropriate for the target version(s) of Office, ensure that it uses the correct namespace, as defined previously.

  3. Modify the package relationship part (.rels) to link the correct XML file and ensure that the relationship type corresponds to the target version of Microsoft Office. For example, if you are creating a solution that targets Office 2010 and you added a customUI2010.xml file to a customUI folder (inside of the Zip package), the newly-added relationship line should look like the following example.

    <Relationship Id="rId4" Type="https://schemas.microsoft.com/office/2007/relationships/ui/extensibility" Target="/customUI/customUI2010.xml" />
    

    As long as it is unique within the .rels file, the relationship Id can have any value.

  4. Close the Zip package and replace the .zip extension with the appropriate extension for your macro-enabled file.

  5. Open the document and ensure that the customizations from your XML file appear.

Note

Although it is useful to know what is going on within the Office Open XML Formats structure, you may be able to bypass these steps. You can take advantage of the Custom UI Editor tool. With this tool, you can open a document, insert a custom UI (with a file targeted to the 2007 release or the 2010 release of Microsoft Office), and then save the document with the XML markup in place. It also enables you to add custom icons and makes it easy to refer to these icons.

Creating a COM Add-In Solution

In a typical scenario, a COM add-in contains code that returns the XML defining the custom UI to Microsoft Office. This XML can be contained in an external file or in simple cases, located in the code itself. When the application runs, the code returns the XML markup to Office. In an optional step, you can validate this XML against a XSD schema file. The XML is then loaded into memory and applied to the Office Fluent UI.

  • If your add-in targets a single version of Microsoft Office, regardless of whether it is the 2007 release or the 2010 release, the markup returned by code should contain the appropriate namespace (as defined previously) and should be valid for the target version.

  • If your add-in targets both the 2007 release and the 2010 release of Microsoft Office, the code should detect which version you are running and based on the check, return appropriate markup. This requires both markup files are authored and accessible by the code. You can rely on the application’s object model (Application.Version) to check which Microsoft Office version you are running.

    Alternatively, you can use reflection to achieve the same thing. The following is an example using Microsoft Visual C#.

    string version = applicationObject.GetType().InvokeMember(
       "Version", BindingFlags.GetProperty,
        System.Type.DefaultBinder,
        applicationObject,
       new Object[0]) as string;
    

Conclusion

How you target each version of Microsoft Office depends on whether you are creating a document-specific solution or a COM-based solution. When creating a document-based solution, you need to ensure that Microsoft Office finds and loads the XML file defining the structure of the customized UI which is appropriate for the target version of Microsoft Office. When creating a COM-based solution, you need to ensure that your code returns the XML defining the structure of the customized which is appropriate for the target version of Microsoft Office.

Additional Resources

For more information about Office 2010 extensibility, see the following resources: