0
votes

I have a Word document that has fields where information is populated by the user manually. There are couple of other documents with same fields and the user would like to populate those automatically, based on information in first document. How to achieve that? Documents are in .doc format.

I've tried looking around before coming here, but every site I've managed to find (that has title of "Filling fill-in forms in Word" and similar) actually describes how to prepare a document for such action, not how to insert the data in from other document. I'm maybe missing something very obvious, but can't figure it out.

All documents have "Allow only this type of editing in the document:" ticket and "Filling in forms" selected under "2. Editing restrictions" in Restrict Editing menu.

1
Did the answer below solve your issue?Cindy Meister

1 Answers

0
votes

This is a borderline question, as it technically falls in the end-user area. But it could also be an interesting question for developers as there is no direct way to achieve what is required using the object model, except by following the steps below (i.e. inserting IncludeText fields).

  • In the source document, it's necessary to use content controls for text input (form field dropdowns work fine) and bookmark them. The content of a legacy form field textbox will not come through.
  • In Word, in the target document, go to Insert->Object->Text from file
  • in the dialog box click the Range button, type in the bookmark name
  • select the option to "Insert as Link"

This creates an IncludeText field in the document that references the file path to the source document and the bookmark content:

{ INCLUDETEXT "C:\\Test\\TestFormsProtection.docx" Text1 }

Note that there is no reliable (sometimes it might work, but other times not) way to use relative file paths with Word field codes.

The relevant VBA code to generate this field at the end of the active document:

Dim doc as Word.Document
Dim rng as Word.Range
Set doc = ActiveDocument
Set rng = rng.Content
rng.Collapse wdCollapseEnd
doc.Fields.Add rng, , "IncludeText " & Chr(34) & "C:\\Test\\TestFormsProtection.docx" & Chr(34) _
    & " Text2", false