News Stay informed about the latest enterprise technology news and product updates.

VSTO and the Tai of the Office object model

In a conversation with Microsoft's Eric Carter and Eric Lippert, the importance of object models is discussed; specifically, a model that can have the same structure a the business model that developers may code against.

Microsoft's Eric Carter and Eric Lippert are important driving forces behind Visual Studio Tools for Office 2005, due to formally ship in a few weeks. Their just-released book, "Visual Studio Tools for Office" from Addison-Wesley Professional (available in part as a free chapter download elsewhere on this site), shows how developers can use Word, Excel, Outlook and InfoPath to create Office-oriented applications in a managed code environment.

Carter and Lippert are both highly versed in Visual Basic for Applications (VBA), which is still a supported development tool in the Microsoft arsenal. Both admitted to the limitations of VBA. The tool, they noted, embedded code in every customized document, making it hard to fix bugs. The VBA model, programming against COM objects, too, had significant security weaknesses. But, as scores of others have found, VBA had merits to try and bring forward.

When planning VSTO, which comes up on its second release with VS 2005, Microsoft looked at how VBA was used. In fact, it was applied by people with varied skills and approaches to programming.

"In designing the system, it was important to us to take a look at how people were using existing VBA solutions," said Eric Lippert.

"We found they had an object model that let them manipulate documents and spreadsheets," he said.

"But people were using [VBA] to build expense reports and invoices. The VBA model forces you to take you business model and map it into the world of the spreadsheet. Meanwhile, what developers like to see is that the Office object model that they code against should have the same structure as their business model."

Under the covers
That is why new-style data binding is so useful. Using .NET, you have an object that meets business needs and you can map it into a document object and have the .NET framework take care of many implementation details.

A recent addition to the VSTO portfolio has been support for Outlook development. The qualities of object design that VSTO applies to other Office products play here as well.

Noted Eric Carter: "I think that what VSTO does for Outlook development is it removes the road blocks that made it difficult in the past to create an Outlook add-in successfully."

"We have done a lot of work under the covers to make sure that your Outlook add-in runs in its own application domain, which ensures it won't be adversely affected by other add-ins," he said.

"In the past you also had to effectively reference-count all the Outlook objects you used and make sure you set them all to 'Nothing' before the add-in would shut down," Carter continued.

"With VSTO, you no longer have to do all that tedious object management --we make sure your add-in unloads and cleans up without you writing any code to do so," he added.

The first version of any software is usually best seen as a stake in the ground. Version 2 [2005] of VSTO should be studied for a broader managed code picture, and for special appeal to VB developers. "This version is the first that tries to provide an end-to-end managed code story," said Carter. He pointed to designers for Word and Excel that let you add WinForms controls to documents. They also let you bind data against name ranges, lists in Excel, bookmarks, and more.

"You drag any forms controls onto the document surface," said Carter, "it is a much richer environment than VB developers had before." VB developers who already do WinForms can use the same style of development to Office development, he said.

"There is not an Office-specific model to learn, for example, about a data bind," he said. Instead, it is the same model as the one developers used in WinForms to insert into their applications.

A good yardstick for developers, said Carter, is whether they can build a similar application using data binding, achieve the same functionality, and then find that the source code looks the same. The new software meets those goals.

With the first version of VSTO it might be said that a lot of people were forced to learn the object model in order to get things done. An aim of the new version is for the framework to abstract the object models so that some developers might be able to work with, for example, an expense report application, while not fully learning the inherent object model.

Eric Carter's colleague Eric Lippert added that this latest VSTO product has special merit for the VB community. He echoes some others who have suggested that VB is a somewhat more apt language than C# for new-era Office development. Capabilities in the VB language make it easier to program against the object model, said Lippert.

Download sample chapter of Visual Studio Tools for Office
Office Development pages- MSDN
Redesign an Excel VBA Solution for .NET Using Visual Studio 2005 Tools for Office - MSDN

Dig Deeper on Visual Studio Tools for Office (VSTO)

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.