custom field in document template RRS feed

  • Question

  • I'm trying to add a (custom?) field to a Word template that I'm using to open and populate a new document from within Excel.  The ultimate idea is to use VBA at the time the file is created to set the field to contain data from the spreadsheet.  However, one step at a time, and for now, it would help just to know how to create an appropriate field in the Word template that can contain a short amount of text.

    [If there is a "non-custom" field that might work for this purpose, that's okay, too -- but it has to be one that's not going to auto-update later and change the value on me.  It would also be nice if the name was meaningful, which is why I thought a custom field would probably be better.]

    Finally, it would also be nice to know, once the document is created, how I can modify the field value within Word if that becomes desirable.

    Thanks for any help anyone is able provide!


    Friday, July 10, 2020 8:51 PM

All replies

  • There are several ways to do this in Word.

    You can insert a Bookmark, then in VBA use the bookmark name to insert text. Bookmarks often disappear when you do this, so this would be a solution for a document that gets filled in once for each instance. Working with Bookmarks in VBA

    You can insert a legacy Formfield, then use the bookmark name of the formfield to set the text as either the formfield Result or as its default text. This would be a potential solution for a fillable form that is distributed to users of both Windows and Mac. Be the Master of Your Formfields

    You can insert a Content Control, then use the Title or Tag attribute to find it for filling with VBA. Content Controls work in Office 2007 and later in Windows and 2016 and later on a Mac, so this is a better solution when you can be certain that users of old versions will not be using the file. Content Controls

    You can insert DocVariable fields, then set those using VBA: How to store and retrieve variables in Word documents

    Saturday, July 11, 2020 4:54 PM
  • I would add to John's excellent response the idea of Custom Document Properties and DocProperty fields. You can manipulate Document Properties from vba and can also access them through the user interface as "Advanced" properties. They are somewhat more accessible to the user than are document variables which can ordinarily only be manipulated through vba.

    There are special document properties in the quickparts menu which are really built-in mapped content controls attached to properties.

    Repeating Data Using Document Properties Content Controls and Other Mapped Content Controls

    Charles Kenyon Madison, WI

    Saturday, July 11, 2020 11:34 PM
  • Hi, 

    Just checking in to see if the information was helpful. Please let us know if you would like further assistance.



    "Office" forums will be migrating to a new home on Microsoft Q&A !
    We invite you to post new questions in the "Office" forums' new home on Microsoft Q&A !

    Tuesday, July 14, 2020 6:40 AM