Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 590
  • Last Modified:

What do I use to display userform data in a Word 2010 template: fields or controls?


I've created a userform in Word 2010 template where users can insert data such as their name, phone number and the add our customer's address and name.

Should I use fields or the new Word controls to display them in the document?

I'm new to Word programming. Thanks for your help/feedback.
Massimo Scola
Massimo Scola
  • 3
3 Solutions
The biggest problem is knowing whereabouts on the document to put the data.

There are various techniques: Legacy form fields,  bookmarks, content controls, tables or replaceable pilot text (e.g. <New Text here>.

Unless you have any problems, then use the new content controls. The main problem is in finding the right one. There is (in 2007, anyway), no direct way of getting a Content Control be name. You will have to step through the ContentControls collection an look for one with the Tag or Title (neither automatically unique) that you have given it.

For the others:

Form fields are easiest to program for, but to work properly, the document must be protected.

Bookmarks can easily be deleted, and require come slightly fiddly programming it you want to replace the existing text.

Tables are quite good, especially if you want to control the precise placing at the same time.

Here are some one-line examples:

Form Fields:

ActiveDocument.FormFields("MyField").Result = TextBox1.Text


ActiveDocument.Bookmarks("MyBookmark").Range.Text = TextBox1.Text


ActiveDocument.Tables(1).Cell(1,1).Range.Text = TextBox1.Text

Content Controls

Activedocument.ContentControls(1).Range.Text = TextBox1.Text
Here is a pilot text example:

    With ActiveDocument.Range.Find
        .Text = "<ReplaceMe>"
        .Replacement.Text = TextBox1.Text
        .Execute Replace:=wdReplaceAll
    End With

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now