18.11.2014 Views

Microsoft Office

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Creating Custom Excel Add-Ins 45<br />

5. Select the Lock Project For Viewing check box.<br />

6. Enter a password (twice) for the project.<br />

7. Click OK.<br />

Creating the add-in<br />

To save the workbook as an add-in, switch to the Excel window and activate your workbook. Then choose<br />

<strong>Office</strong> ➪ Save As. Select <strong>Microsoft</strong> Excel Add-In (*.xlam) from the Save As Type drop-down list. Enter a<br />

name for the add-in file and then click OK. By default, Excel saves the add-in in your AddIns directory, but<br />

you can choose a different directory if you like.<br />

Creating the user interface for your add-in macro<br />

At this point, the add-in is created, but it’s missing one key component: A way to execute the macro that<br />

displays the UserForm. This section describes how to modify your add-in file so that it adds a new button<br />

to the Ribbon. It uses a technique known as RibbonX, which involves XML.<br />

In previous versions, Excel’s user interface was very easy to modify. Even a relatively inexperienced<br />

user could add a new toolbar button and attach a macro to it. Things have changed with<br />

Excel 2007. Modifying Excel’s user interface is much more complicated. The following example is, admittedly,<br />

a very simple one. A complete discussion of RIbbonX is well beyond the scope of this book. In fact,<br />

entire books are devoted to this topic.<br />

NOTE<br />

Specifically, we’ll add a new group that’s displayed when the Home tab is clicked. This group will contain<br />

one button, and clicking this button will execute the ChangeCaseofText macro.<br />

The changes you need to make are done outside of Excel. Make sure that the add-in file is not open in<br />

Excel. You’ll need to use a text editor. such as Notepad.<br />

1. Create a folder named customUI.<br />

2. Inside of that folder, create a text file named customUI.xml, with the following XML code:<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

Note that this XML code refers to the macro, ChangeCaseofText. That explains the argument<br />

that’s required in the Sub procedure declaration, listed earlier in this chapter (see “Procedures in<br />

Module1”).<br />

779

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!