Including Check Boxes on an MS Word Merge Document

From SmartWiki
Revision as of 12:13, 22 June 2009 by Cameron (talk | contribs)

Jump to: navigation, search

This article explain how to use the data stored within SmartSimple to determine whether or not a Check Box on an MS Word Merge document is checked.


The MS Word Merge Custom Field allows you to merge text stored within SmartSimple into an MS Word document. You cannot merge information directly into a Check Box Form Field on the MS Word document to make it checked or unchecked.


Note: these instructions are for MS Word 2003. If you are using a different version the steps may vary. Please consult MS Word Help for assistance.


Create a Text Form Field, then double-click on it and enter a name in the “Bookmark” field.


The field (named sourcefield in this example) is where the merge data is stored. When the MS Word Merge document is opened, a macro will use this value in this field to determine whether or not the associated checkbox should be checked. The field will then be deleted by the Macro.


Next create the “Check Box Form Field”, double-click on it and enter a name in the “Bookmark” field. Be sure that you have created a “Check Box Form Field”, not just a Check Box. 0

The “check box form field” is named target in this example


Finally open the Tools menu > Macro > VB Editor and add the following script:

Private Sub Document_Open()

    '--- Exit if an error is encountered
    On Error GoTo ExitSub

    '--- define variables
    Dim source As Bookmark
    Set source = ActiveDocument.Bookmarks("source")

    Dim target As CheckBox
    Set target = ActiveDocument.FormFields("target").CheckBox

    '--- check the source text and tick the associated target checkbox if appropriate
    If (source.Range.Text = "CheckMe") Then target.Value = True
 
    '--- Delete the source field
    source.Range.Delete

ExitSub:
End Sub

The user who performs the MS Word Merge must have Macros enabled for MS Word or it will not run.

  • Macros can be enabled via the Tools menu > Macros > Security
  • The setting can be set to either Medium or Low. Medium is recommended, which means the user will have to agree to allow the Macro to run each time the document is opened.


Note: when you are creating the original MS Word Merge document you will need to disable Macros while you work on the document. Otherwise the source “Text Form Fields” will be deleted by the Macro each time you open the document. You should only allow the macro to run when you have actually created the document via the MS Word Merge in SmartSimple.