Share via

Word Template auto insert rows based on form field

Anonymous
2014-02-24T16:23:07+00:00

I would like to make a template that would auto insert rows based on a number in another field in the document - for example:

The employee performed [insert a number here] tests (tests #__ through #__).

And in another section it would automatically make the number of rows and number them in a table:

Test Number Type of Test

So, if I entered in [5] in the number of tests then the table would automatically look like this

Test Number Type of Test
1
2
3
4
5
Microsoft 365 and Office | Word | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

22 answers

Sort by: Most helpful
  1. Jay Freedman 207.7K Reputation points Volunteer Moderator
    2014-02-24T23:09:52+00:00

    You'll need a macro to do this. The macro can be selected as the "exit macro" in the properties dialog of the form field in which the number of rows is specified, so the macro will run when the cursor leaves that form field.

    In the code of the macro, you'll have to turn off the forms protection, insert the requested number of rows, and then turn the protection on again.

    In order for the macro to know where to insert the rows, you'll have to use some method of locating the correct table. For example, if the table is the first (or only) table in the document, you could have the macro add rows to ActiveDocument.Tables(1). Or you could insert a bookmark named "TestTable" around the table, and the macro would add rows to ActiveDocument.Bookmarks("TestTable").Range.Tables(1).

    If you need more help with the macro, post back.

    Was this answer helpful?

    2 people found this answer helpful.
    0 comments No comments
  2. Charles Kenyon 167.7K Reputation points Volunteer Moderator
    2014-02-24T23:16:02+00:00

    Next Question:

    Protected Form?

    Legacy form fields (compatible with Word 2003 and earlier) or Content Controls?

    Legacy forms are protected for filling in forms, second is protected from editing with exceptions (your fields). These should generally not be mixed.

    Either will require macros. These cannot be recorded but have to be written. Thankfully, much of the work has been done and posted online by others.

    While you are waiting for me or someone else to respond, you can look here:

    Look at Forms in the MVP page on Fields and Forms.

    Look at Field, Forms and Protected Documents on the MVP VBA page.

    Installing Macros

    Making Forms with Microsoft Word

    Word Content Controls

    Developer Tab

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments
  3. Charles Kenyon 167.7K Reputation points Volunteer Moderator
    2014-02-24T19:16:20+00:00

    What you want can be done, but why not simply have the user tab to create the rows as needed? When you tab out of the last cell of a table, it automatically creates a new row with formatting based on the previous row. Tables

    The style for the Test Number cell could be set to automatically number.

    How to create numbered headings or outline numbering in Ribbon Versions of Word by Shauna Kelly

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments
  4. Anonymous
    2014-07-07T13:52:35+00:00

    Can anyone provided the macro to do this? I was a form that needs this but dont know how to create a macro.

    Any information will be greatly appreciate.

    Cynthia

    Was this answer helpful?

    0 comments No comments
  5. Anonymous
    2014-02-24T20:43:24+00:00

    I want this to be in protected form.  On one page of the form it tells how many then on the other it would create that number of rows you would need to fill-in.  It would have to be a rule or formula somewhere.

    Was this answer helpful?

    0 comments No comments