2007 for developers

At the Office System Developer Conference in Seattle in March, Bill Gates and Steven Sinofsky boasted that Office 2007 would be “amazing”, “revolutionary” and “dramatically better” for not just the end user but also the developer who wants to build solutions using Office. Would you expect them to say anything different? They also opined that Office 2007 “bridges the gap” between structured and unstructured data, since its new OpenXML file format allows you to put structured data into unstructured documents while still keeping the structure intact. They also took the opportunity to announce a new organisation and website, openxmldeveloper.org, which will promote the use of and information about these new file formats. In an effort to smooth the transition to the new formats, Microsoft has also agreed to release more information about the old binary file formats for Word, Excel and PowerPoint than has been available up until now.

2007 for developers

The new file formats were covered in some depth in later sessions at the conference, but Microsoft hopes end users won’t see much of a difference. It’s releasing converters so that older versions of Office (2003, XP and 2000, but not Office 97 or earlier) will be able to open and save the new files. However, these new formats bring with them many new features that will get lost or degraded when converted back to or opened with older versions of Office. For example, opening a complex Word 2007 document with an older version of Word will work if you just want to read or print the file, but I wouldn’t want to edit that document in the older application and then send it back to a Word 2007 user to finish off – too many of the new features would have become mangled by then. For instance, Content Controls, the new replacements for form fields, bookmarks and XML Tags, will get replaced with plain text when opened in Compatibility mode, which loses all the Content Controls’ validation and protection settings and their links to XML data in the document – you won’t get these things back when you re-open in 2007. Simpler documents will fare much better and, if all a document contains is text and images with paragraph and character formatting, you shouldn’t see many problems.

At the moment, Excel’s converters aren’t doing nearly so well as Word’s. Excel 2007’s graphics are so far ahead of even Excel 2003 that simple line graphs won’t appear right. Excel 2003 and below have a limited number of colours, and the placement and formatting of legends and axes can be sent awry on conversion. These faults will probably be fixed by October, when Office 2007 is due to be released to businesses, but there are still many new features that can’t be directly represented in the older versions of Excel at all. The new Table feature, for instance, has great filtering, formatting and summary features, but under the older versions these are downgraded or absent, leaving you with just the static data.

PowerPoint is in an interesting position when it comes to compatibility with previous versions. Its major new functionality lies in the new diagramming tool and, if you try to edit a slide that contains a diagram using an older version of PowerPoint, the only thing you’ll be able to do is move or resize the entire diagram. This may result in the diagram looking squashed if you don’t resize it proportionately. Open the presentation again in PowerPoint 2007 and all the diagramming tools are available again to work on the diagram you resized, and it may also get redrawn to its previous aspect ratio and so look slightly different. This is a good compromise: the diagram behaves like a static image while being edited in previous versions but preserves all its rich data behind the scenes for use when it gets back to Office 2007.
Programming in 2007

When it comes to programming against the new file formats, there are huge opportunities. The new Word, Excel and PowerPoint document files are actually ZIP containers with the separate parts of the document stored in files and folders inside the ZIP file. You can write applications that replace graphics or data in a Word document simply by manipulating those parts within their ZIP container, and without touching the Word object model at all. Digging deeper, structured data in a document is held in one or more custom XML files within the ZIP container, and any process that knows how to read and write XML can open these data parts and read or change the data, again without having to work with the Word object model.

For interacting with the individual Office applications, there’s still the VBA (Visual Basic for Applications) programming environment. There are many solutions out there that rely on VBA, and Microsoft has pledged that it will continue to be available for as long as is necessary. However, for writing new solutions, it now recommends that programmers move from using VBA in documents and templates and instead use VSTO (Visual Studio Tools for Office) to produce managed code. To go with Office 2007, VSTO 3 will let you create Add-Ins for Access, Excel, InfoPath, Outlook, PowerPoint, Project, Publisher, SharePoint Designer, Visio and Word as well as Smart Documents and Templates for InfoPath, Excel and Word. Add-Ins for the various Office components allow you to add functionality to the application itself, not just to a document or template. Whatever you want to do with Office, the answer will almost always be to produce an Add-In, which will be able to add its own controls to the new Ribbon user interface. Such Add-Ins will also be able to create application-level Task Panes and display as many of them at once as they need, rather than the current, rather limiting one-at-a-time that’s possible in Office 2003.

The Ribbon user interface employs a strictly declarative model for adding command tabs, command groups and controls. Instead of writing code to add your own menus and buttons to CommandBars, you write an XML file that declares all your tabs, groups and controls. When your Add-In starts up, the host application will ask you for this declaration. When it’s time to display your UI, the application will ask for any images required, and if one of your controls gets clicked it will call the appropriate method in your code, which you specified in the XML file. This so-called callback mechanism permits a looser coupling between UI design and code, so that the UI can be rejigged by a designer without requiring the code to be changed at all. The XML file and the images for the buttons can all be included in your Add-In DLL as embedded resources. Sample code provided with VSTO 3, currently available as a CTP (Community Technology Preview), shows how to do this, including code to convert .NET images to the stdOLE.iPictureDisp format used for Office icons. If you don’t want to design your own icons, you can reuse any icons in Office just by specifying their icon ID, and Microsoft has committed to publishing all the icons and their IDs for just this purpose.

You can add your own tab with groups and controls, or else you can add groups and controls to an existing tab or add controls to an existing group. To specify their positioning, you say you want to add your group or control after an existing built-in control by specifying that control’s ID. There’s no way to add a control to the Ribbon while your Add-In is running, so if you think you may need a control at some point you need to declare it upfront and then specify that it isn’t visible until you need it.
One great advantage of this formal declarative model for RibbonX is that the host application knows when to add and remove your Add-In’s UI – there’s absolutely no chance of your controls hanging around when your Add-In isn’t loaded. This has been a big problem with the CommandBar user interface of previous versions, as once a toolbar or button has been added it’s left to your code to remove it again. If you don’t tidy up properly on exiting, those buttons and toolbars will still be there the next time the user runs the host application, even if your code isn’t there to respond to them.

One big restriction is the inability to customise the mini-bar or any right-click menus. This may arrive in later versions, but isn’t planned for Office 2007. Also, the placement of your tabs, groups and controls isn’t guaranteed. You can request placement after an existing tab, group or control, but groups and controls do move around a bit as the window width changes. Large buttons become smaller, they lose their text labels and finally disappear from the main ribbon onto a pop-up group as the user shrinks the window further and further, and these changes may well affect the position of your controls.

By the time Office 2007 finally ships, I expect there’ll be a Ribbon UI design tool that allows you to drag and drop controls to lay out the tabs, groups and controls, but for now you’ll have to hand-craft the XML yourself. One useful setting in the RibbonX schema is Start From Scratch – if your Add-In sets this to True, all the standard controls of an Application get hidden, leaving just the controls the Add-In supplies. If you arrange for this Add-In to launch only when called from a special shortcut, rather than every time the application loads, you’ll get a highly focused application based on Word, Excel or PowerPoint without all the distraction of the usual interface.

Split personality

The new Ribbon UI is available in Word, Excel, Access and PowerPoint, and in all the Inspector objects (the items) in Outlook. Outlook’s Explorer objects (the main windows) and all the other applications retain the old CommandBar interfaces. Microsoft justifies this state of affairs by saying that the other applications aren’t nearly so complex and so don’t need the Ribbon UI to simplify their user interface. I expect that if the Ribbon is judged a success, as I believe it will be, it will be used for all Office applications in the future, and that this was merely a pragmatic decision about how much resource Microsoft deployed this time round to revamp the user interface versus how much to implement the new features of the applications. It chose to put the new UI only into the biggest and most complicated applications, which is all well and good, but as a result it’s ended up giving Office 2007 (and Outlook 2007 in particular) a split personality.

Existing code for Word, Excel and PowerPoint that manipulates CommandBar objects or templates that contain custom menus and toolbars will still work, but all their menu items and toolbar buttons will be gathered together onto a special Ribbon tab called Add-Ins. (All Add-In menus and toolbars end up in the same tab because there’s no way for the host application to know which Add-In created them.) All the host application knows is that it’s been ordered to create the items, but it can’t know which Add-In issued that order. Hence, if you need your solution to work well with both Office 2007 and previous versions, you ought to consider providing both the RibbonX user interface and the CommandBar version in the same package by checking the version of the host application as your Add-In loads and having it act appropriately.
If your existing Office-based solutions employ VBA user forms, you might consider recoding them to use Task Panes instead. Previous versions of Office were restricted to having just one Custom Task Pane, also referred to as the Document Actions Pane. If you needed more than one, you had to allow the user to switch between them as you could only have one visible at any time. Task Panes are a very good way to support modeless interaction between the user and the document, and you can also use them to provide extra information to the user or to perform more complex interaction with the document than would comfortably fit onto the Ribbon. It’s easy to set up a Custom Task Pane and you can put into it any Windows Forms controls. You just have to create a UserControl to define the layout and handle its events (a UserControl is just a miniature form with no borders or furniture of its own). If your solution requires multiple Task Panes, the user can show and hide them, and move them about, making them either float or else dock against any edge of the host application’s window. You might want to put multiple Task Panes into a dictionary object in your code so that you can refer to them by name.

There’s a large number of VBA solutions out there and, if you have some you’re thinking of upgrading to use Office 2007, you could either rewrite their code completely or, if there’s a large amount of already written and tested VBA code, you might consider leaving this as it is but wrapping it within a new .NET shell using the Ribbon and Task Pane user interface. Microsoft did this recently with one of its own internal applications, reusing thousands of lines of VBA and changing only the user interface. This decision-support application was written in Excel 2003 and then upgraded to an Excel 2007 Add-In by using VSTO 3 CTP. All the functions that had nothing to do with the user interface were preserved in Excel VBA, and the programming team wrote a simple class in managed code that could call any function and pass it the correct parameters. Significant time and money savings can be realised by reusing code in this fashion – converting code from VBA to VB.NET or C# is time-consuming and will necessitate extra testing. Reusing your VBA code unchanged reduces the development and testing times, but will still enable you to create a better looking and easier-to-use solution.

So will the situation for Office solution developers indeed get “dramatically better” with the release of Office 2007 as Gates and Sinofsky claimed? Well, 2007 certainly opens up a range of new possibilities and offers new – and yes, better – ways of doing things. However, it also makes life more complicated in some ways. Sure, you can keep using VBA as you have done for ten years now, but the new user interface, file formats and features in the applications will all present significant learning challenges to the developer. There’s a long list of older features that have been modified, deprecated or even dropped completely, which could mean unwelcome changes for quite a few people. To make the most of Office 2007 from a developer’s perspective, you’ve really got to move on from VBA to VSTO, which this time around has really grown in capabilities. Beta 2 of Office 2007 will be available for anyone to try in a couple of months, and developers should grab this opportunity and a copy of the VSTO 3 CTP and see what they can do.

Disclaimer: Some pages on this site may include an affiliate link. This does not effect our editorial in any way.