Export (0) Print
Expand All

Exploring the Dynamic World of Word 2007

Office 2007

Summary: Explore what you can do with dynamic content in Microsoft Office Word 2007, including using fields, document building blocks, and content controls. (5 printed pages)

Watch the Video: Exploring the Dynamic World of Word 2007

If you create Microsoft Office Word 2007 documents and templates for others to use, you might often think about ways to create dynamic content. For example, consider the following scenarios:

  • You need to create alternating headers in a template without enabling the Different Odd and Even header and footer option.

  • You want to provide the user with multiple boilerplate text options at several points throughout a long document template, such as a report, proposal, or contract.

  • You need the same content to populate automatically in several places in a document and automatically update all instances whenever you change one.

In previous versions of Word, you might use fields for tasks such as the one in the first bullet or even the second. But, while you may find other workarounds or use Microsoft Visual Basic for Applications (VBA) to approximate the scenarios listed here, complete and elegant solutions are not so simple.

In Word 2007, fields are still an excellent solution for tasks such as the one in the first bullet. But Word 2007 also introduced content controls and building blocks, two powerful features that greatly simplify many scenarios for working with dynamic content such as those mentioned here.

This article explores the dynamic content you can create with fields, content controls, and building blocks in your Word 2007 documents and introduces you to what you can do when interacting with those features through VBA and Office Open XML.

If you ask me what my favorite feature is in any previous version of Microsoft Office Word, I will say fields without hesitation. Because I create a lot of complex documents, my fondness for tables is profound and my relationship with styles is a bit closer than you might consider healthy. But fields are fun. Fields enable you to easily customize documents in ways that may otherwise seem impossible. In fact, when you think about it, working with fields is a lot like simple programming.

But, if you ask about my favorite feature in Word 2007, I have to hesitate. Powerful new features such as building blocks and content controls, and the ability to customize document content using Office Open XML, exponentially expand the options for creating more customized and more dynamic content. I can’t choose just one favorite anymore, but fields are still high on the list. In some ways, you can go much further with other features (as addressed later in this article), but fields remain an important and often easy solution to customizing or creating many types of dynamic content. So, before moving on to new features, consider an example of how far you can go using fields.

Say that you need to display the document title and the current top-level heading in alternating page headers. However, you prefer not to use the Different Odd and Even Headers and Footers option in this document for workflow reasons. Instead, create a nested field code using an If statement along with the Mod function (to determine whether the page is odd or even) and display the appropriate result.

{If{=Mod({Page} + 2, 2)} = 1 "{Title}" "{StyleRef "Heading 1"}"}

Each pair of brackets {} in the example represents a field code. To reproduce this example in your document, do not type the brackets. Instead, select the text within each pair of brackets and press Ctrl+F9 to convert that text to a field code. This example contains a total of five nested field codes.

All other characters shown in this example are required for the field syntax. For example, quotation marks are required around the Title field and StyleRef field because they represent the results the If evaluation. The first pair of quotation marks indicates the result of the If evaluation to display if the condition is true (in this example, the document title) and the second pair indicates the result to display if the condition is false (in this example, the most recent Heading 1 paragraph text). Also note that spacing is required in some parts of this nested field, such as the spaces surrounding the number 1 at the end of the If statement.

Notes

  • To learn some advanced basics and shortcuts for creating and customizing fields, see the blog post Let's Talk About Fields, Baby!.

  • If you are comfortable creating complex nested fields like this one but you think that extensibility in the 2007 Microsoft Office system (such as writing VBA macros and editing Office Open XML) is too complicated, guess what? You are already using Microsoft Office extensibility tools by writing your own custom fields. So, you might just be amazed at how much you can do very easily using VBA and Office Open XML. To learn what you can do with these powerful extensibility tools, see Taking the 2007 Office System Further with VBA and Open XML Formats.

    (And, thanks to one of my favorite Word developers, Rob Paulsen, for showing me this odd and even header trick several years ago and inspiring me to go further with Microsoft Office extensibility.)

If you have much experience with Word 2007, you might already know that you can make the preceding nested field example even more dynamic by using a Document Property Quick Part content control for the title instead of using the Title field.

Content controls in Word 2007 are the evolution of form controls and they also represent an important step in the evolution of documents. Because content controls are created using XML, it is very easy to pass data into and out of these controls. So, you can use content controls the same way you used form controls in previous versions to enable users to complete a form or complete information at identified points in a document. But, you can also bind data to those controls from another source to automatically populate and update document content using sources ranging from document properties to custom data on a SharePoint site or other Web service.

For example, several predefined content controls are automatically bound to document property data and provided in Word 2007 as Document Property Quick Parts, including one for the document Title. If you insert several Title Quick Parts in the same document (such as on the cover page, in the header, and in an appendix), you can change the title in any of those Quick Parts or in the Title field in document properties and the title automatically updates in all instances. Data binding in Word 2007 documents works in both directions so that you can update data either from the data source or from within the control.

To access all available Document Property Quick Parts, on the Insert tab click Quick Parts and then click Document Property.

To insert a content control that is not automatically bound to data, insert the control from the Controls group on the Developer tab. Seven types of content controls are available in Word 2007, including rich text, plain text, picture, combo-box, drop-down list, date picker, and building block gallery controls.

Notes

  • After you insert a content control, on the Developer tab, in the Controls group, click Properties to name the control and apply preferences such as formatting options. Also in the Controls group, click Design Mode to view the XML tags for your controls and to edit placeholder text.

  • To learn more about working with content controls in the Word 2007 user interface (UI), see Chapter 11: Content Controls: Creating Forms and Then Some, excerpt from Advanced Microsoft Office Documents 2007 Edition Inside Out.

  • Binding your own data to content controls does require some use of either the Word object model or Office Open XML. However, several resources are available to help you learn about how to bind data to content controls. In fact, one great place to start is with information straight from the Word product team, such as Taking Advantage of Bound Content Controls, a blog post from Word program manager Zeyad Rajabi.

    You can also download the Content Control Toolkit, a free, open-source tool that greatly simplifies the process of binding data to controls, and explore the excellent tutorial available from that link as well.

If you used AutoText in previous versions of Word, you are already familiar with some of what you can do with building blocks. In fact, building blocks are the evolution of AutoText. You can save text and other document content in any Word 2007 template as a building block entry and use familiar shortcuts to insert (F3) or save new (Alt+F3) entries. But, that is essentially where AutoText leaves off and building blocks just get started.

Word 2007 provides several built-in galleries for different types of building block entries, as well as the ability to create your own custom galleries which you can add to the Quick Access Toolbar or to a Ribbon tab that you customize. Built-in building block galleries include Cover Page, Quick Tables, Header, Footer, Page Number, Text Box, Quick Parts, Watermark, Equation, Table of Contents, and Bibliography.

Many types of building blocks also provide additional functionality. For example, when you click to insert a cover page from the Cover Page gallery on the Insert tab, Word automatically adds that cover page as the first page of your document. If you then click to insert a different cover page from that gallery, the original is automatically replaced. However, like many types of building block entries, cover pages are typically created using Document Property Quick Part (bound) content controls, so when the cover page is automatically swapped, content that you added to the controls on the original cover page remains.

Notes

  • Right-click on an entry in many building block galleries for additional options, such as the option to insert a cover page in a different location than the start of the document.

  • To edit the properties of a building block entry, including deleting an entry or moving it to another category, gallery, or even another template, use the Building Blocks Organizer. To access the Building Blocks Organizer, on the Insert tab click Quick Parts and then click Building Blocks Organizer. Or, right-click an entry in any built-in building block gallery and then click Organize and Delete.

  • Building blocks and content controls work together in several ways. For example, use the Building Block Gallery content control type to place a building block gallery in the body of a document or template, such as when you need to provide the user with access to several options for boilerplate content at various points in a document.

As you can begin to see just from the overview in this article, content controls and building blocks greatly expand on your ability to work dynamically with content in Word 2007 documents. And, when you use Office Open XML, you can exponentially increase the power of content controls with data binding.

Of course, when you create content for others to use, you might look for even more ways to interact with these powerful features. For example, you may want to conditionally filter the options that display in a drop-down list content control or programmatically populate a custom building block gallery. That's where VBA comes in to help you take your documents, templates, and document solutions even further. See the additional resources that follow to learn more.

Stephanie Krieger is a Microsoft Office System MVP and the author of two books, Advanced Microsoft Office Documents 2007 Edition Inside Out and Microsoft Office Document Designer. As a professional document consultant, Stephanie helps many global companies develop enterprise solutions for Microsoft Office on both platforms. She also frequently writes, presents, and creates content for Microsoft. You can reach Stephanie through her blog, arouet.net.

Show:
© 2014 Microsoft