How to create smart document templates

This page explains how to create “smart” documents templates in Microsoft Word, using quick parts, to display document metadata from SharePoint inside the actual document, e.g. the page header/footer, e.g:
Document metadata displayed on a page header
To add an embedded metadata, follow these steps:

  1. Add the site columns that should be added as metadata, to the document template library (see instructions here).
  2. Open a Word document from the document templates library.
  3. Place the marker in the document where you want to add the quick part.
  4. Select the “Insert” tab in Word and, in the “Text” section, then “Quick Parts” and depending on which metadata you want to add, you either select “Document Property” (for all custom columns and certain word properties) or “Field” (for certain standard SharePoint columns):
    Inserting Quick Parts
    In the section “Standard SharePoint columns as embedded Metadata” bellow, you will see which quick parts to choose, for standard SharePoint columns.
  5. Select the appropriate quick part.
  6. If needed, format the inserted quick part (font, font size, font color, etc.).
  7. Save and close the document.
  8. New documents that are created from the template will now contain the Quick Part (metadata).

Standard document properties as embedded metadata

These standard document properties can be added as embedded metadata:

  1. Name
    1. “Name” is the document’s name, including its file-extension.
    2. Can be added as an embedded metadata in documents, by inserting the “FileName” Field Quick Part.
    3. Unfortunately this field does not automatically update when you open a document. Here you find instructions on how to make this field updated, manually or automatically.
  2. Created
    1. Can be added as an embedded metadata in documents, by inserting the “CreateDate” Field Quick Part.
    2. Unfortunately this field does not automatically update when you open a document. Here you find instructions on how to make this field updated, manually or automatically.
  3. Author
    1. Can be added as an embedded metadata in documents, by inserting the “Author” Field Quick Part.
  4. Modified
    1. Can be added as an embedded metadata in documents, by inserting the “SaveDate” Field Quick Part.
  5. Modified by
    1. Can be added as an embedded metadata in documents, by inserting the “LastSavedBy” Field Quick Part.
    2. Unfortunately this field does not automatically update when you open a document. Here you find instructions on how to make this field updated, manually or automatically.
  6. Title
    1. “Title” is a regular document column that users can update, if the column is available in the documents’ content type, as mandatory or optional.
    2. It can be added as an embedded metadata in documents, by inserting the “Title” Document Property Quick Part.
    3. This column is synchronized with the documents’ “Title” property.
  7. Document ID
    1. Can be added as an embedded metadata in documents, by inserting the “Document ID Value” Document Property Quick Part (only shown if you have activated the “Document ID Services” feature).

Document version number as an embedded metadata

Unfortunately there’s no easy and foolproof way to show a document’s version number as an embedded metadata inside a document. It is however possible to create a custom flow that does this but it requires some development effort which could be offered by MetaShare’s development team.

Other Document Property Quick Parts that can be used as embedded metadata

Apart from the file properties mentioned above, other file properties can also be added as Document Property Quick Parts. Some of these can be set, from Microsoft Word, by clicking on the document’s “File” tab, selecting “Info”. The properties are located under the “Properties” section:
Other file properties that can be added as Quick Parts

These properties plus a few more, can also be set and updated from within Word, by first adding them as Document Property Quick Parts and then updating their values:

Quick Part’s nameAvailable as File property?
Abstract 
AuthorYes
CategoryYes, as “Categories”
CommentsYes
CompanyYes
Company address 
Company E-mail 
Company Fax 
Company Phone 
KeywordsYes, as “Tags”
ManagerYes
Publish Date 
Status 
StatusYes
SubjectYes

How to update fields in Word

Unfortunately some embedded “Document Property” fields, e.g. “Name”, are not automatically updated when you open a Word document. The field will however automatically be updated when you switch to print preview, if “Update fields before printing” in Word Options is set to yes:
Update fields before printing

If you want to manually update a field in the document, just select the field and then press F9 on your keyboard.

You can otherwise create a Word Macro that does this automatically for you when you open any document, the disadvantage of this is that all documents will be modified, when you open a document and you will be asked if you want to save your changes when you close the document even if it is only opened in read-only mode. To do this you have to:

  1. Click on Word’s “Developer tab”, and then click “Macros” in the “Code” group.
  2. In the Macros dialog box’s “Macro name” field, type: AutoOpen.
  3. To make the Macro run on all documents that you open in Word, select to store the macro in “All active templates and documents” in the “Macros in” field.
  4. Click the “Create” button.
  5. In the code sheet of the Microsoft Visual Basic editor, you should now see the beginnings of your AutoOpen macro. It will look like this:
    Sub AutoOpen() ' ' AutoOpen Macro End Sub
  6. Copy and paste, the following macro code into your AutoOpen macro, before the last line:
    Dim aStory As Range
    Dim aField As Field
    For Each aStory In ActiveDocument.StoryRanges
    For Each aField In aStory.Fields
    aField.Update
    Next aField
    Next aStory
  7. Your AutoOpen macro should now look something similar to the this:
    Word macro that update fields
  8. On the File menu and click on “Save”.