Please Note: This article is written for users of the following Microsoft Word versions: 97, 2000, 2002, and 2003. If you are using a later version (Word 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Word, click here: Using Sequential Document Serial Numbers.

Using Sequential Document Serial Numbers

by Allen Wyatt
(last updated February 16, 2015)

14

If you have a need to create serial numbers in your documents and they are very simple in nature, you can do so using a macro. This approach to serial numbers is great if your serial numbers are sequential (1, 2, 3, etc.) or regular in their incidence (3, 5, 7, etc.).

To begin, you should enter the macro that will control the change of the serial number and the printing of your document. You can use the following macro:

Sub MySerial()
    Dim rngSerialLocation As Range
    Dim intSerialNum As Integer
    Dim strSerialNum As String
    Dim docCurrent As Document
    Dim intNumCopies As Integer
    Dim intCount As Integer

    ' set ref to current active doc
    Set docCurrent = Application.ActiveDocument
    ' set ref to the bookmarked serial number
    Set rngSerialLocation = docCurrent.Bookmarks("Serial").Range

    ' get the starting number
    intSerialNum = Val(rngSerialLocation.Text)
    ' get the number of copies required
    intNumCopies = Val(InputBox$("How many Copies?", _
      "Print Serialized", "1"))

    For intCount = 1 To intNumCopies
        ' print the document
        docCurrent.PrintOut Range:=wdPrintAllDocument
        ' increment the serial number
        intSerialNum = intSerialNum + 1
        ' put into formatted version
        strSerialNum = Format(intSerialNum, "00000")
        ' stuff into proper place
        rngSerialLocation.Text = strSerialNum
    Next intCount

    ' reset the bookmark, since the updating procedure
    ' wipes out the old one
    docCurrent.Bookmarks.Add Name:="Serial", _
      Range:=rngSerialLocation
End Sub

There is only one prerequisite to using the macro: you need to make sure that your document contains a bookmark named Serial. This bookmark should reference the serial number in your document, as you want it to appear in the first printed document. (When you are through running the macro, you can save the document and the serial number will be ready for the next time you want to use it.)

The macro also assumes that your serial number consists primarily of some numeric value that changes with each iteration. You can modify the incrementing of the serial number, as well as its formatting, in the For...Next loop within the macro.

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (1747) applies to Microsoft Word 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Word (Word 2007 and later) here: Using Sequential Document Serial Numbers.

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. ...

MORE FROM ALLEN

Controlling How Word Displays ScreenTips

ScreenTips can appear with or without shortcut keys displayed in them. Here's how to control whether they appear or not.

Discover More

Encrypting a File Folder

Want to make the data stored on your system more secure? Think about enabling the built-in encryption capabilities of Windows ...

Discover More

Moving the House Number to Its Own Cell

Excel is great at manipulating data, but sometimes it is difficult to figure out the best way to do the manipulation. This ...

Discover More

Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!

More WordTips (menu)

Printing Copy Numbers

Copy 1, Copy 2, Copy 3... Do you want to mark your printouts so that they are numbered? Here's how you can do it.

Discover More

Printing More than One Copy

If you need to print more than one copy of your document, you need to become familiar with the options in the Print dialog ...

Discover More

Triple-Spacing Your Document

Print your document with lots of space between each line—triple space it! Here's some quick and easy steps for getting ...

Discover More
Subscribe

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

View most recent newsletter.

Comments

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 four less than 4?

2016-09-26 09:44:36

Marshall Burke

Works great except for the automated printing output. Thank you. But how can I modify the macro code so that when I run the macro and increase the count by one, a copy of the previous numbered document is not printed. I do not want an automated printed copy and want to control that printing function in the normal way. I do want the serial number to increase by 1 when the macro is run.
Thanks.


2016-08-01 15:54:26

John

Hi and thanks for the Tip.
Very interesting.
Is there a way to output all documents in a unique Pdf files please?

Thanks and Regards
John


2016-03-09 09:14:35

Erich

Works awesome. Thanks.


2015-07-07 14:39:18

Chir

Oh -- and Thank you Allen!


2015-07-07 14:37:39

Chir

Hello everyone! This Macro seemed to work for me except for the fact that the macro is printing 2 copies of each iteration of the document I added the Macro to. I looked through the Macro to see if I could identify a line that was causing the duplication, but did not notice anything I could put my finger on.

Could this be because I am trying this on a multiple pages document? Has this happened to anyone else? If so, how did you fix this issue? Thanks!

Steve - Are you running the Macro to print the document or doing File- Print as you normally would? Running the Macro to print worked for me, except for the issue I mentioned in the paragraph above. (I'm noticing that your comment was posted in March-so perhaps this feedback is a tad bit untimely)


2015-06-11 03:39:09

Amir

Awesome, when I run the macro, I get very nice result! thanks a lot!

I bookmarked a text as: Serial

as you have told.

Very Nice!


2015-03-18 17:07:01

Steve

Try as I might, I cannot get the serial number to increment.

It may be the sequence and process for a) adding the macro and b) adding the bookmark.

A bookmark named Serial has been added. A single bracketed digit appears at the bottom right of the single page document: [1]

When opened, VB shows one macro named MySerial, flagged as (General).

The number prints, without the brackets, but does NOT increment. Could sure use this sometime today/tonight.

Thanks,
Steve



2015-03-06 18:36:41

Patrick

We have been using this for a couple years when it suddenly stopped working and giving us an over flow error.

Figured out we had reached the limit of the Integer setting of -32,767 to 32,767 when our sequence reached 32767. Changed the dim listings from "Integer" to "Long" and all is good again.

Greatly appreciate this macro and the time it has saved us.


2013-02-13 16:08:21

John K

This macro is exactly what I was looking for. However, is it possible to execute the macro when a users attempts to Click on File>Print or clicks the printer icon?


2012-09-19 16:57:17

Roy Jensen

A workaround: put the serial number in the header or footer. This doesn't work if you have a different first page or non-continuous headers between sections.


2012-09-19 00:31:29

Roy Jensen

I've got this to work, but I would like to print the serial number on EVERY PAGE of the document.

* I've tried referencing the bookmark, but that doesn't work.
* I've tried bookmarking the entire serial number, but that doesn't work.

Any ideas how to do this?

Thanks,
Roy


2012-09-05 08:12:15

Geza

Hi Alan,
I managed to get help on this forum, you can read the whole thing here:

http://www.msofficeforums.com/word-vba/12959-sequential-document-numbering.html

but if you only need the final result I can send it to you if you post your email address here (in the text area) making sure that you're using some dummy characters instead of "@" something like allan{at}abc.net, this way spam sending email address harvesting robots won't see it as an email address.


2012-09-04 20:04:29

Allan

Hi Geza, I'm starting off too. I figured out that on the main document you need to click the "Bookmark" icon on the "insert" tab (Word2010). It will ask you a prompt word. You just type in the word "serial" then run it. Just remember to place the curser where you want the serial number to be placed before you bookmark it.

My issue is that it does not request the starting number, it just goes to how many copies...still trying to figure that out.


2012-05-16 08:01:12

Geza

Hi,
I get an Run-time error '5941':
The requested member of the collection doesn't exist.

Debug:
Set rngSerialLocation = docCurrent.Bookmarks("Serial").Range

Can you help?


This Site

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

Newest Tips
Subscribe

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.