Please Note: This article is written for users of the following Microsoft Word versions: 2007 and 2010. If you are using an earlier version (Word 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Word, click here: Auto-incrementing Form Fields.

Auto-incrementing Form Fields

by Allen Wyatt
(last updated October 3, 2016)


When you are working with forms, you save the forms as templates that are used as the basis of new documents in Word. There may be times when you want to add a form field that increments every time you create a new document based on your form template. For instance, you might have a sequence number that you need for a data input form, or you may want to use a form field to indicate an invoice number.

Word does not have any fancy auto-increment fields. However, by combining some of the tools already available in Word, you can create a template and form field to do the trick for you. Start with this macro:

Sub AutoNew()
   ' Exit macro if no fields in document
   If ActiveDocument.FormFields.Count = 0 Then Exit Sub
   ' Create variables.
   Dim OfficeAppName As String
   Dim RegSection As String
   Dim RegKey As String
   Dim FieldObj As Object
   Dim RegValue As Long

   OfficeAppName = "Word 2007"
   RegSection = "UserData"
   RegKey = "Current Counter"
   ' Generate error if form field doesn't exist
   On Error GoTo ErrHandler
   Set FieldObj = ActiveDocument.FormFields("IncField")
   ' Get stored registry value, if any
   RegValue = GetSetting(OfficeAppName, RegSection, RegKey, 0)
   ' If not previously set, set to default
   If RegValue = 0 Then RegValue = 1
   ' Set form field result to stored value
   FieldObj.Result = CStr(RegValue)
   ' Increment and update invoice number
   SaveSetting OfficeAppName, RegSection, RegKey, RegValue + 1
   If Err <> 0 Then
      MsgBox Err.Description
   End If
End Sub

This macro should be saved only in the template that you will use to create your forms. The macro must be named AutoNew, so it will run whenever a document is created that is based on the form template. You should also make sure that you have a text form field in your document named IncField, which will display the incremental number. The number is tracked in the Registry so it can be accessed for future forms.

Notice the line in the macro that sets the OfficeAppName variable. In this version of the macro, it is set to the phrase "Word 2007". If you are using a different version of Word, you should modify this line so it refers to your version, such as "Word 2010".

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (11431) applies to Microsoft Word 2007 and 2010. You can find a version of this tip for the older menu interface of Word here: Auto-incrementing Form Fields.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He  is president of Sharon Parq Associates, a computer and publishing services company. ...


Turning Off Word's Second Guessing with Quote Marks

When you type quote marks in a document, Word normally changes them to Smart Quotes. They look better on a printout, but ...

Discover More

Changing Orientation of a Text Box

Want to change how a text box is oriented on the page? You can't do it, but you can adjust the dimensions of the box ...

Discover More

Using Optional Hyphens

Adding hyphens to your document can affect the way in which Word wraps text from one line to the next. Optional hyphens, ...

Discover More

Learning Made Easy! Quickly teach yourself how to format, publish, and share your content using Word 2013. With Step by Step, you set the pace, building and practicing the skills you need, just when you need them! Check out Microsoft Word 2013 Step by Step today!

More WordTips (ribbon)

Creating Traditional Forms

Do you use Word to create printed forms? If so, here's some ideas and techniques you can use to make those forms look as ...

Discover More

Spell Checking Forms

Word may be used to create protected forms that limit where the user may input data. Normally spell checking is disabled ...

Discover More

Entering Calculations in a Form Field

One of the many uses for Word is to create forms that can be easily filled in by other people. This is made possible by ...

Discover More

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.


If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is one more than 5?

2016-07-21 13:40:53

Eleanor Flynn

I have been trying to set up a court transcript page with Questions and Answers; each question being a consecutive number. Is there any way in Word to do that?

2014-01-31 12:23:34

John McMullen

An additional problem with using the registry is that a large corporation might set the policies to restrict the registry. That's true where I work, for instance: the IT department keeps a short (sometimes too short!) leash on adding or changing the registry.

2013-05-08 11:29:36

Barry Fitzpatrick

Storing the value in the registry has got its limitations/issues:

1. the registry value is only accessible on a single machine, so sharing the file is not feasible (unless duplicate values are acceptable).

2. the value could change if say a "System Restore" to an earlier time is actioned or if the OS software is re-installed.

3. The value is lost if the files are transferred to another machine, e.g. say, if the User upgrades to a new machine.

4. the stored value may not be backed up, if the back-up only archives data and not the registry.

5. Opening an existing document will increment the stored number.

An alternative is to use a "Custom Document property" which lives with the document. (This tip "" describes how to create one), just store it in the FormField itself.

On opening the template/master document runs the "AutoNew" macro which increments the stored value and saves it back to the template/master file. Next it saves itself to some randomly named non macro-enabled file (effectively deleting the macro & releasing the template file for use by someone else in a shared environment)pending the User giving it a final name. If there are other macros that need to be preserved then another Custome property would need to be set to indicate the AutoNew routine needs to exit without incrementing the stored value or changing the filename.

As mentioned above as this is a macro the file needs to be stored as a macro enabled file. MS-Word security settings have to be set to allow the macro to run.

2013-02-07 18:20:43


After I spend many hours figuring out that Mr What was making the assumption we all know as much as him, and figure that there are missing steps for Word 2007. This works beautifully.

The missing steps I found, are that you must create a "Macro Enabled" Template for this code to work and "Form Fields" are the LEGACY form fields, not the 2007 - 2010 new Text fields.

I hope this helps others.

This Site

Got a version of Word that uses the ribbon interface (Word 2007 or later)? This site is for you! If you use an earlier version of Word, visit our WordTips site focusing on the menu interface.

Newest Tips

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.