Loading
Word.Tips.Net WordTips (Menu Interface)

Using Sequential Document Serial Numbers

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.

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.

Related Tips:

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!

 

Comments for this tip:

John K    13 Feb 2013, 16:08
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?
Roy Jensen    19 Sep 2012, 16:57
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.
Roy Jensen    19 Sep 2012, 00:31
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
Geza    05 Sep 2012, 08:12
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.

Allan    04 Sep 2012, 20:04
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.
Geza    16 May 2012, 08:01
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?

Leave your own comment:

*Name:
Email:
  Notify me about new comments ONLY FOR THIS TIP
Notify me about new comments ANYWHERE ON THIS SITE
Hide my email address
*Text:
*What is 3+4? (To prevent automated submissions and spam.)
 
          Commenting Terms
 
 

Our Company

Sharon Parq Associates, Inc.

About Tips.Net

Contact Us

 

Advertise with Us

Our Privacy Policy

Our Sites

Tips.Net

Beauty and Style

Cars

Cleaning

Cooking

DriveTips (Google Drive)

ExcelTips (Excel 97–2003)

ExcelTips (Excel 2007–2013)

Gardening

Health

Home Improvement

Money and Finances

Organizing

Pests and Bugs

Pets and Animals

WindowsTips (Microsoft Windows)

WordTips (Word 97–2003)

WordTips (Word 2007–2013)

Our Products

Premium Newsletters

Helpful E-books

Newsletter Archives

 

Excel Products

Word Products

Our Authors

Author Index

Write for Tips.Net

Copyright © 2014 Sharon Parq Associates, Inc.