Category

Microsoft Office 2010

Level

Expert

Smart data entry

Smart data entry in your Word 2010 document template

Summary

Many templates require user input to be added in a specific location. Enter CustomXML and ContentControls in Word. This tutorial will teach you how to add your own data in a word template, and offer user friendly input to your users using a Document Information Panel.

Goal

In this tutorial the reader will learn advanced techniques to manipulate the contents in a Word document in order to enable end users to easily enter data without the use of any macros. Because there is no Graphical User Interface present in Word 2007/2010 there will be some VBA-programming involved.

Audience

Office Developers who distribute Word 2010 templates to groups of end-users

Prerequisites

  • (optional)Shared location to enable Document Information Panel. For example networklocation or Sharepoint

Required knowledge

  • Basic XML
  • Word 2010 advanced
  • Word 2010 Visual Basic for Applications (VBA)
  • InfoPath 2010

Required tools

  • XML editor. Preferably one that validates like Altova XML Spy.
  • InfoPath 2010 (for creating a Document information Panel)
  • Word 2010

Tutorial lessons

This tutorial exists of a number of lessons which must be followed in order to reach the desired effect. Please review each step by clicking on the title

0 - Overview

Before entering all the separate lessons I will try to give an overview.
Now you have a global picture of the steps we will take to create a working template. The next steps will provide detailed information about these steps.

1 - Create an empty template

We will create a simple Word 2010 template file, that will be expanded with all the features.
We now have a simple template containing a header, some text and a footer.

2 - Add Content Controls to Word document

In this step we will replace some text that the user should enter by so called 'Content Controls'.
We now have a document containing content controls that can be used to enter data. We applied some properties for our new content controls so they can be easily used by users.

3 - Design XML file

After setting up the content controls we will look at all the unique pieces of information in the content controls. Each unique information part needs a separate XML element to hold that information. Later we will add this XML file to our Word document.
We now have an XML file that can contain all unique pieces of information.

4 - Add XML to Word

In this step we will add the XML file from your harddisk to the Word document/template.
Now we have the means to create and update your CustomXMLPart in the Word document. If you need to make changes to the CustomXMLPart you will make these changes to your local XML file and replace it in Word using your macros.

5 - Link Content Controls to Custom XML

In this step we will link the content controls to elements in de CustomXMLPart. This is in fact an optional step: the Content Control doesn't require storage in a CustomXMLPart; it's fine working on its own. The power of linking a content control are described in this lesson.
We now have linked all the content controls to a storage location in the CustomXMLPart. We did this by calling the SetMapping method passing an XPath expression. To find a Content Control in the Word document we used the function SelectContentControlsByTag to find a Content Control by the value of the TAG attribute. It's not always necessary to link a Content Control to customXMLPart. I briefly discussed some reason when you should consider linking.

6 - Smarter linking Content Controls

In this lesson we will look at how to create a smarter method for linking Content Controls to the right CustomXMLPart. This is done by adding an attribute in the XML file that indicates the value of the tag-attribute belonging to the Content Control
We now have a generic macro we could move to a Word Add-in because it operates independent of the Word document/template.

7 - Placeholder text

If there is no text in a Content Control, the placeholder text is displayed in light gray. It is possible to replace this standard text (from Microsoft Word) with your own text.
You now have a macro and XML file that will enable you to assign a custom placeholder text.

8 - Protection

In this lesson we will have a look at securing the content controls. This is not a very sophisticated way of securing things: everybody can easily remove the security. So, securing thing is a way to prevent users from accidentally removing controls or their contents.
Now we have a template that can be deployed to users, without running the risc of users breaking it.

9 - Create Document Information Panel

In this lesson we will take the user experience once step further: creating a so called Document Information Panel (DIP). This is a panel that is shown when a document is opened and can be styled using images, tables, colors etc. Only downside is that this DIP cannot be integrated in the Word document structure, and must be on a shared location all users can access.
We now have an even better way to let users input information. A nice panel with some extra checks, so users shouldn't even have to look for all the content controls.

10 - Create a Word Add-in

We now have a template with macros that will only work for this template. Wouldn't it be great to have these macros available all the time?
Now you have a set of macros available when starting word.

Tags