What's New in Microsoft Office Word 2003 for Developers?

Summary: Review what's new in Microsoft Office Word 2003 for developers. Learn about the hot new XML features, smart documents, and smart tags. Also read about collaboration possibilities with Microsoft Windows SharePoint Services and security enhancements available in Word 2003 as well as how to use Microsoft Visual Studio Tools for the Microsoft Office System to create custom solutions for Word 2003. (6 printed pages)

Don Kiely, Information Insights

October 2003

Applies to: Microsoft Office Word 2003, Microsoft Office System, Microsoft Visual Studio Tools for the Microsoft Office System

Contents

  • Overview

  • The Word 2003 XML Story

  • The Word 2003 .NET Story

  • Object Model Enhancements

  • Word 2003 and Microsoft Windows SharePoint Services

  • Security in the Microsoft Office System

  • Conclusion

Overview

Microsoft Office Word 2003 promises to be an improved platform for developing custom solutions. Although this new version has all of the same development tools as Microsoft Word 2002—including Microsoft Visual Basic for Applications (VBA) and its editor—Word 2003 has even more and better features for developing automated, intelligent documents more easily than ever before.

Many of the improvements arise directly from the use of XML in Word 2003 as both a native document format and as the structural foundation for many new features. With its close ties to the .NET Framework, you can write code and interface tools using any COM-based technology or any .NET-compliant language.

The Word 2003 XML Story

One of the difficulties in working with Word documents in the past was associating meaning with the content of a document. All of the information was locked in the proprietary binary format of Word. You could access the data programmatically via the object model and its COM objects (or do some messy parsing of an RTF document), but this method was limited at best and required way too much programming to get at the data.

Word 2003 takes advantage of XML to unlock the content and enable several flexible new ways for both a user and code to interact with a document, its content, and its formatting.

One use of the XML is to define the structure of data that the user enters into a document using an XML schema, as shown in Figure 1. Users have the full benefit of the rich document-editing features of Word 2003 while being assured of entering data in the structure required by the application. Users can save such documents as the XML data only, as XML data plus formatting using the WordML schema, or with an XSLT transformation that modifies the structure of the XML data.

Figure 1. Associating an XML schema with a document allows you to enter highly structured data

Entering highly structured data

You can learn about using the XML features with Word 2003 from the documentation and samples included in the Microsoft Office Word 2003 XML Content Development Kit. The kit describes how to programmatically load and use schemas with Word 2003 documents, how to navigate the robust WordML schema, ways to open and save XML documents and data in Word 2003, and how to manage schemas and other XML features in a document.

By using XML as a native part of its document structure, information in a Word 2003 document becomes available for any kind of programmatic use, including robust document management, data mining and retrieval, and easier programmatic manipulation of documents. This new feature promises to impact how developers build solutions based on Word 2003.

Smart Documents and Tags

One of the benefits of developing solutions based on Office documents is the ability to automate documents to guide the user and to enforce an organization's policies. In the past, you had to write custom code to interact with the user. You could create powerful solutions, but it took a lot of development time to get it all working right.

The Microsoft Office System builds a rich infrastructure, based on developer and customer feedback, to make creating solutions faster and more productive. Two of the key technologies that help Office 2003 developers make better solutions are smart documents and smart tags.

Smart Documents

The new XML support in Word 2003 provides the foundation for a whole new way of creating custom solutions based on a type of Word document called smart documents. These structured documents use an XML schema to gather information from a user in combination with a custom task pane. The task pane can be used to guide the user through the application, prompting for data to add to the document, helping the user navigate the solution, and validating both the structure and content of the information.

You can build smart document solutions based either on an existing or new Word 2003 document. An XML schema defines the structure and content of the data in the document, just like other XML-based documents. Then you can write code to automate it by implementing the ISmartDocument interface defined in the smart documents type library, and creating forms for the custom task pane that guides the user. The solution can hook into the collaboration features of the Microsoft Office System to route documents to various people, such as to a manager to approve a project proposal before it is sent to a client.

Smart documents are smart in other ways, too. One of the problems with working with document-based solutions in an enterprise is that you can easily have multiple versions of a document on the network and on individual computers. Smart documents solve this problem with XML Expansion Packs, a kind of manifest that resides on a server and contains a list of the solution's required files and its current version. Information about where to find this manifest is embedded in the smart document. Every time the user runs the solution, it can automatically update itself with any new files and code so that users always run up-to-date versions of the solution.

Smart Tags

Smart tags, introduced in Microsoft Office XP and greatly expanded in Office 2003, recognize text in a Word 2003 document and provide a menu of actions that a user can take, such as inserting text into a document based on an order number. Smart tags provide a large part of the functionality of smart documents. In fact, the two technologies are so closely related that your solutions reference just a single type library to use either or both in your solutions, the Microsoft Smart Tags 2.0 Type Library.

Smart tags in Word 2003 are both easier to develop and have better user interface features than in Word 2002. By implementing the two new interfaces ISmartTagRecognizer2 and ISmartTagAction2, you can hook into the new features in your solutions. For example, one new option for smart tags includes cascading menus that better organize complex lists of options for users. You can also implement dynamic captions that change at run time, based on the user and any other conditions you implement in code. Best of all, the smart tag model is streamlined across all applications in the Microsoft Office System, making it easier to write tags that are usable in all the applications.

The Word 2003 .NET Story

The Microsoft Office System hooks into the .NET Framework. Using Microsoft Visual Studio Tools for the Microsoft Office System, you can build .NET Framework applications in Microsoft Visual Studio .NET that have nearly the same intimate relationship that VBA code has to documents. Visual Studio Tools for the Microsoft Office System supports Word 2003 and Excel 2003 document applications, providing new document and template projects for both Microsoft Visual Basic .NET and Microsoft Visual C.

The secret to this magic is a set of custom properties embedded into documents and properties created using Visual Studio Tools for the Microsoft Office System, as shown in Figure 2. When Word 2003 opens a document with these properties, the .NET Framework loads along with the assembly in the location specified by the _AssemblyLocation0 property. The assembly responds to events and has full access to the Word 2003 object model.

Figure 2. The custom properties in a Word 2003 document created with VSTO hook into a .NET assembly that interacts with events

Word document properties hook into .NET assembly

An application written using Visual Studio Tools for the Microsoft Office System doesn't execute within a document the way a VBA application does. Instead, it interacts with the document through Primary Interop Assemblies (PIAs), special wrappers provided around the COM objects in Office 2003. Using these tools, you can write document-based applications that take full advantage of the .NET Framework.

You can also incorporate the Framework into custom Word 2003 applications by creating Word 2003 add-ins using .NET components. This lets you take advantage of the COM interoperability features of the Framework to wrap native .NET components in type libraries, making them appear similar to the COM objects used in Word 2003 and VBA Editor interfaces.

Object Model Enhancements

As with every new version of Office, the object model expanded to incorporate new features, giving you programmatic access in both VBA and .NET Framework applications. Many of the extensions to the Word 2003 object model center around its enhanced support for XML. But there are plenty of other goodies even if you don't take advantage of XML in your applications.

XML Support

Besides letting you automate all of the XML-related tasks that a user can do in Word 2003, the new XML features in the object model let you manipulate every XML feature in a document or template. You can attach and manage schemas in the schema library for Word 2003; add, change, and delete XML elements in a document; save the document as XML that contains only the data from the document or as a rich WordML document; transform the XML in a document using an XSLT template; respond to events when the user makes changes to XML data; and validate all or portions of the XML data against an XML schema.

The object model accomplishes all this through a combination of new objects and enhancements to existing objects. A couple of the more interesting new objects are the XMLChildNodeSuggestion object that provide a list of potential child elements of the current element when a user is creating or editing XML based on a schema. You can manage XML namespaces with the XMLNamespace object and its collection, and apply XSLT transformations with the XSLTransform object and the XSLTranformations collection.

The Application object has new support for XML namespaces and events that fire when the XML changes or a validation event occurs. The Document object sports many new properties and events, such as the ability to customize the interface seen by the user, to customize how Word 2003 saves an XML document, and to fire more events when the user inserts or deletes XML in the document.

Object Support for Other Features

There are several welcome additions to the object model that help manipulate documents. For example, the new Break object and its collection provide an easy way to work with the page, column, and section breaks in a document. The Page and Pages objects let you define page layout in the document. Several new smart tag objects support all the new capabilities of this Word 2003 feature.

The list of new properties, events, and methods is quite extensive. Some, such as the Document object's EnforceStyle property that specifies whether to enforce the formatting restrictions of a protected document, make it easier to build controlled document applications. Others support new features, such as the Window object's Thumbnails property that controls the new thumbnail view of a document in the task pane in a document.

Word 2003 and Microsoft Windows SharePoint Services

A major benefit of using the Microsoft Office System in an enterprise is its strong collaboration features. Users can jointly develop the content for a Word 2003 document, comment on it, and make changes that Word 2003 tracks and automates. They can collaborate by using e-mail, or set up a shared workspace site on a network server using Microsoft Windows SharePoint™ Services (formerly Windows SharePoint Team Services from Microsoft) to provide a location for working together on documents and managing the process. Users can interact with this workspace site using the Shared Workspace task pane, shown in Figure 3, and set various options for how Word 2003 interacts with the workspace site, as shown in Figure 4.

Figure 3. The Shared Workspace task pane lets a user interact with a SharePoint site

Workspace task pane lets a user interact

Figure 4. Use Service Options to configure shared workspace settings

Configure shared workspace with service options

Such shared workspace sites can form the basis for custom collaborative solutions that hook into XML-based documents.

Security in the Microsoft Office System

Security is a top priority for Microsoft, and Visual Studio Tools for the Microsoft Office System builds on that focus. This new version includes all of the user and code protections of Office XP, such as password protection for documents and code, the ability to digitally sign VBA projects, and protections for the user's privacy. Moreover, most of the default security settings in Word 2003 are set to high levels of protection, such as High for macro security.

Developers who build Word 2003 solutions with Visual Studio Tools for the Microsoft Office System work within the additional security requirements and environment of the .NET Common Language Runtime (CLR). The CLR provides both code-access and role-based security. Code-access security restricts or grants permissions to code, based on its origin and other rules, called "evidence." This means that code downloaded or run from the Internet is inherently not trusted, and code from the intranet could be fully trusted with access to all resources or restricted in ways you define. Role-based security is similar to the security model in Windows (any version) in which a user can have permissions granted or revoked directly or through membership in a group or role.

Deploying solutions for the Microsoft Office System built with the .NET Framework must consider these security models and may require that you modify the local or enterprise security policies as necessary.

Conclusion

Word 2003 builds on its predecessors to provide new support for document-centric solutions. With its thorough support for XML and the tools and framework for building smart documents, it is very easy to integrate Word 2003 in custom solutions.

About the Author

Don Kiely is a senior technology consultant. When he isn't writing software, he's writing about it, speaking about it at conferences, and training developers in it. Reach him at donkiely@computer.org.