Tips and Tricks For Using MS Word to Automate Templates

From HotDocs Wiki

Jump to: navigation, search

This article should give you an understanding of how Microsoft Word works as it relates to HotDocs. Specifically, it teaches:

  • The "hierarchical" structure of Word and the basic understanding as to how Word works.
  • The underlying processes to create HotDocs templates and clauses in Word.
  • The importance of the paragraph symbol and numbering as they relate to HotDocs templates.

Contents

Hierarchical Structure of Word

Word’s formatting functionality is based on a hierarchy of character, paragraph, and page settings, each of which gives you an easy way to create and adjust formatting. This section describes each part of the hierarchy and its use in Word.

Character Formatting

Character formatting is the most basic type of formatting that is applied to individual characters or symbols. This includes character size and attributes like bold, underline, and italic. You can apply character formatting to a single character or multiple characters. Character styles allow you to define a specific look for a character that can be easily copied throughout a document and later modified if you want all characters with that style to be modified in a single step. For example, to apply bold character formatting to a single word, highlight the word then click the Bold button (or use the keyboard shortcut Ctrl+B). To apply character formatting to several words or a few characters within a word, highlight the text you want to modify and then apply the formatting as described above.

Paragraph Formatting

The paragraph mark () is an important feature in the basic structure of Word. Information regarding paragraph formatting is stored in the paragraph mark. The paragraph formatting applies to entire paragraphs at one time and includes the following attributes:

  • Text alignment
  • Line spacing
  • Spacing between paragraphs
  • Tab stop settings
  • Indentations from left and right margins
  • Borders and shading
  • Bullets and shading
  • Position in the page layout
  • Text-flow properties in relation to page breaks


If the at the end of a paragraph is deleted, the next paragraph will merge with the preceding one, and adopt its formatting and style. This can confuse developers who do not understand the significance of paragraph marks in Word. Some developers work with the marks visible, so that they can avoid accidentally deleting this symbol. If you accidentally delete the and want to restore the paragraph mark and the original formatting, click the Undo button or use the keyboard shortcut Ctrl+Z.

Section Breaks

Page and Section formatting lets you set options like the margins, page orientation (landscape or portrait), line numbers, headers, footers, etc. Page formatting for the entire document can be established at the Page Setup dialog box (File menu). You can use section breaks (choose Break from the Insert menu) to modify the page setup for different parts of the document. For example, section breaks can be inserted to print a full-page table in the middle of the document in landscape view, while the rest of document prints in portrait view.

Sometimes, when working with inserted templates, you want different sections of the assembled document to use different headers/footers. This is controlled through the use of section breaks. For additional information on doing this, see the topic in the HotDocs Help on using headers and footers in inserted templates.

Styles

All of the characters in a Word document have a style. When you create a new document, the document contains styles based on a template called Normal.dot. The default style is usually the Normal style. You can change the format of individual characters in the styled paragraphs without changing the style itself. Word simply remembers that the paragraph or characters are, for example, Normal + Italics.

Styles define the appearance of various text elements of your document, such as headings, captions, and body text. When you apply a style to a paragraph or word, you can apply a group of characters or paragraph formats in one simple operation. When you want to change the formatting of all of the text of a particular element at once, you just change the style that's applied to that element. Styles make formatting your document easier. In addition, they serve as building blocks for outlines, paragraph and heading numbering, and tables of contents.

Creating HotDocs Templates in Word

As you create Word templates, it's helpful to understand just how the template is created. This can help you troubleshoot problems you may encounter with styles, etc.

Template Format

When HotDocs loads a template for assembly, it opens the template, converts it to Rich Text Format (or RTF), and then assembles the document. Depending on the size and complexity of the template, this conversion to RTF may slow the speed with which the document is assembled. Because of this, it is recommended you create templates in RTF, rather than DOT. Doing so eliminates that conversion step and speeds up the process with which HotDocs is able to assemble your document.

Global Templates

HotDocs integrates with Word through the use of global templates. When Word is started, it looks at its Startup folder and loads any of the global templates that are saved there. HotDocs installs and uses two global templates—Hd6icon.dot and Hd6edit.dot. Hd6icon.dot places the HotDocs button on the toolbar, and Hd6edit.dot adds the HotDocs toolbar to the word processor, which allows you to automate templates and assemble documents from within Word. These templates must be loaded for HotDocs to work correctly.

Create a Text Template

As explained earlier, when you create a new Word document (independent of HotDocs), Word uses Normal.dot as the base template. When you create a new text template, however, HotDocs uses a different template, Hotdocs6.dot, as the base. This template contains the HotDocs Edit toolbar, as well as all of the macros required to create and edit variables, manage the component file, and so forth.

How HotDocs determines what styles to use in a template depends on how the template is created. When you create a new, empty template, HotDocs applies whatever styles are in HotDocs6.dot to the new template. When you create a new template based on another template or document, HotDocs applies the styles used in that template or document to the new template.

Paragraph Symbols and Numbering

Paragraph Marks Inserted and Removed By Instructions

When automating a template, paragraph marks are added in the following situations:

  • After the closing chevron of a REPEAT instruction (i.e., «REPEATDialog»¶)
  • After the closing chevron of an END REPEAT instruction (i.e., «END REPEAT»¶)
  • After the closing chevron of an IF instruction (i.e., «IF Variable»¶)
  • After the closing chevron of an END IF instruction (i.e., «END IF»¶)
  • After the closing chevron of a SPAN instruction (i.e., «SPAN Name»¶)
  • After the closing chevron of an END SPAN instruction (i.e., «END SPAN»¶)
  • After the closing chevron of an INSERT instruction (i.e. «INSERT Template.rtf"»¶)
  • After the closing chevron of an ASK instruction (i.e. «ASK Dialog»¶)

When HotDocs adds a paragraph mark during automation, it will remove the paragraph mark during assembly. Basically, it checks to see if there is a paragraph mark immediately following the instruction. If there is, it removes it in the assembled document.

When inserting multiple IF / ELSE IF instructions or expressions in a template, consistency in spacing between instructions is imperative. For example, if you highlight the blank line below a paragraph when conditioning it, you should highlight the blank line below every paragraph you condition. For a complete discussion on how to do this, see Develop Correct Line Spacing for IF Instructions.

Line Breaks and Paragraph Ends

Microsoft Word distinguishes between paragraph marks () and line breaks (). A paragraph mark ends one paragraph and starts a new paragraph, while a line break simply starts a new line of text in the same paragraph.

By default, when you create a multi-line Text variable, if the user presses Enter in the answer field, HotDocs treats the return as a line break. For example, the following shows how a three-line address field merges the address in the document:

Variable Merged Answer
«Client's Address» 123 Redwood Road↵
Suite 456↵
Provo, UT 84606¶

If you need HotDocs to instead merge a paragraph mark when the user presses Enter, you can select the Enter key in multi-line answers inserts new paragraph mark (¶) option at the Text Variable Editor. Doing so formats an answer like this:

Variable Merged Answer
«Client's Address» 123 Redwood Road¶
Suite 456¶
Provo, UT 84606¶

When creating a computation script that merges a multi-line text answer, you can control which mark is used. You can do this by entering a key combination in the script:

Key Combination Script Merged Answer
Pressing Enter or Shift+Enter creates a line break Address Line 1 + "
" + Address Line 2 + "
" + City + ", " + State + " " + Zip Code

Caution:Pressing Enter or Shift+Enter in the
script does not insert a visible character or
mark in the script.

123 Redwood Road↵
Suite 456↵
Provo, UT 84606¶
Pressing Ctrl+Enter creates a paragraph break Address Line 1 + "¶
" + Address Line 2 + "¶
" + City + ", " + State + " " + Zip Code

Caution:Pressing Ctrl+Enter in the script
inserts an actual paragraph mark character
in the script.

123 Redwood Road¶
Suite 456¶
Provo, UT 84606¶

Paragraph Numbering

When numbering paragraphs in a template, you can use HotDocs numbering, or you can use Word numbering. Unless you are building templates for both WordPerfect and Word users, it is recommended you use Word numbering.

To create paragraph numbering using Word, either apply a List style to the text, or highlight the text and click the Numbering button. If you have optional paragraphs, you can create your IF instructions either before or after you number the paragraphs.

A numbered set of paragraphs might look like this (with Show/Hide ¶ on):

Paragraphnumbering.png

Notice that «IF Paid Seminar Days» and the corresponding «END IF» are numbered. Don't worry about this because, as explained earlier, any paragraph symbol following either an IF or END IF statement will be deleted upon assembly, along with any formatting (like the paragraph numbering).

Additional Information

The following articles contain additional information on working with Word templates: