Jack McIntyre » Microsoft http://jackmcintyre.net Mostly talking about beer Sat, 25 Jun 2011 08:01:12 +0000 en hourly 1 How to add macros to the Excel 2007 Ribbon http://jackmcintyre.net/how-to-add-macros-to-the-excel-2007-ribbon/ http://jackmcintyre.net/how-to-add-macros-to-the-excel-2007-ribbon/#comments Thu, 02 Apr 2009 18:20:00 +0000 Jack http://jackmcintyre.net/?p=56 As much as I dislike using Microsoft products, sometimes, you have no choice. In our work with salesforce.com, the Excel Connector is a huge time saver. We use it for a number of things, and it is far superior to the data import functionality of salesforce.com. In the upgrade from Office 03 to Office 07, custom toolbars were lost. I spent quite a while looking for the ‘custom ribbon’ in Excel 07 – it does not exist. Here is what you need to do to build a tab in the ribbon, add buttons for your macros, and embed both the customisations and the macros in an add-in (for deployment). I still have a few little changes to make, but everything is working with it set up like this.

  1. Create a new workbook in Excel
  2. If you do not already have your macros recorded, do that. If you do have them recorded, go into VB mode and copy the module(s) into your new blank workbook. Save the workbook as <add-in name>.xlam
  3. Download and install the Custom UI Editor Tool
  4. Start the custom UI Editor, and open your .xlam file. Now you can start customising the appearance of the ribbon. My code looks like this at the moment:
  5. Once you have edited the xml for your ribbon customisations, save and exit the Custom UI Editor Tool, and start excel. Next, activate your add-in. That code should get you something that looks like this:
  6. Here is an example of how each of my macros is coded. Note the main macro, and the smaller one above that references it:
  7. Once you are happy with it, you can distribute your .xlam file, complete with macros and ribbon enhancements. All the recipient needs to do is activate the add-in.

To be completely honest, I don’t fully understand the reason for using callbacks in macros. I believe it is so that you can continue referencing the original macro elsewhere (without the “control As IRibbonControl” bit). The ribbon has copped a lot of hate since its launch, but I don’t think it’s all that bad. I’m actually getting used to it. While the process of customising it is challenging (to say the least), I think the results are pretty professional. You have far more power than is demonstrated in my example. It looks like you can get pretty creative in your ribbon design – there are plenty of options for button types, images, etc on this page. It took me long enough to get it this far though :)

UPDATED: Here is a template to use in the custom UI editor. Replace “onAction” text with callbacks to your macros, and change the label to suit.

]]>
http://jackmcintyre.net/how-to-add-macros-to-the-excel-2007-ribbon/feed/ 1