Working with XML

Because XML is case sensitive, it is easy to make errors that might be difficult to find. You can turn on error messages for the Ribbon so that you are notified of the type of error that occurred, rather than the application simply not displaying the customization.

❖ Note: You could have added a new Format tab in addition to the built-in Add-Ins tab, rather than replacing it.

For example, in the XML code shown in Listing 14.2, if you change the case of idMso to idMSO and then run the code, you'll see that this one error causes the entire customization to fail, and the Format Tab tab does not display. Without knowing the cause of the error, you might spend considerable time looking through the XML markup to find it. You can turn on error messages for UI customization as follows:

1. Click the File menu (this is the big round button known as the Microsoft Office button), and then select Options. In this case, it will be for Excel Options, but this particular setting works in all Office applications that support UI customizations.

2. In the left pane, select Advanced, and then scroll down to General in the right pane.

3. Select the Show Add-in User Interface Errors check box, as shown in Figure 14.14, and then click OK.

Figure 14.14. Displaying UI errors for add-ins

Now when you run the same code, you'll get an error message that indicates that an error was found in the XML description of the custom UI of a particular add-in. It also gives information about what the error was, such as the attribute idMSO not being defined in the schema, as shown in Figure 14.15.

You can enable IntelliSense for the XML markup to help reduce typing errors. Microsoft provides a schema for the Ribbon called CustomUI.xsd that you can reference in your add-in and enable IntelliSense for the XML markup. You can find this schema by searching for "2007 Office System: XML Schema" on the Microsoft Download Center. Save the

Error Loading Custom UI XML

An error occured while loading the add-in with progID "5ampleAddin":

An error was found in the XML description of the Custom UI of an Addin: Line: 9 Column: 39

Error Code 0x80004005

The attribute "idMSO" on the element '-(' is not defined in the DTD/Schema.

Figure 14.15. Ribbon error

CustomUI.xsd file to the \Program Files\Microsoft Visual Studio 8\XML\Schemas directory and add a reference to the file in the Project properties of your add-in.

This schema provides IntelliSense as you work in the XML file in Visual Studio. For example, if you want to add an attribute that enables a screen tip for a control, type screen, as shown in Figure 14.16. The IntelliSense drop-down appears and displays the attributes available for the control.

■itoggleButton idMso=rrBold" screen] /> </group> </tati> </tatis> </rikikion> -i/customUI>

Jff insertBeforeQ

'if teytip

¿j> label

Jff onAction

Ply screentip

^ showlmage

Jff showLabel

iff size

^ supertip

S1 tag


Figure 14.16. Displaying IntelliSense

As you saw in Listing 14.2, the idMso attribute of the toggle button you added is set to "Bold"; this name is self-evident, but it can be challenging to figure out the names (or control IDs) for the rest of the buttons. In the application's Options dialog box you can display control IDs for all the built-in controls.

1. Click the File button and then select Options. In this case, it will be for Word Options, but this setting displays the controls and control IDs for each individual application.

2. In the left pane, select Customize. In the right pane, you will see options for customizing the Quick Access toolbar. Later in this chapter you'll learn more about the Quick Access toolbar.

To see the control ID for a control, select a command from the dropdown, and then hold your cursor over a button in the list. The control ID is displayed in a pop-up, as shown in Figure 14.17.

Figure 14.17. Displaying control IDs

In this case, the control ID is TextAllCaps. If you want to use one of the built-in icons, but not the default functionality, for your button, you can set your control's imageMso attribute to that same control ID. This eliminates the need to find a control's faceID, because the icon has the same name as the control (the control ID). You can download a list of all the control IDs on the Microsoft Download Center by searching for "2007 Office System: List of Control IDs".

0 0

Post a comment