Page tree

Welcome to FreeSoftwareServers Confluence Wiki

Skip to end of metadata
Go to start of metadata

There are two methods I have found to achieve this goal, I will leave the second method, but I don't use it since it required a separate text file outside the document. Method 1 stores the number in a custom document property.

The idea is I have a single page document and each time it prints should have a unique incrementing number so I can track say, I have doc # 45 to employee John  Smith.

I would reccomend reading through Create Simple Greeting Macro - Word - Microsoft Office if you are new to Macros.

Also, you will want to have this automated once it works as expected via this post >> Run Macro Before Printing - Word - Microsoft Office

Here is my final product which is "portable" for you to explore:


Method 1:

Sub FilePrint()
Dim i As Long, j As Long
With ActiveDocument
  j = CLng(InputBox("How many copies to print?", "Print Copies"))
  For i = 1 To j
    With .CustomDocumentProperties("Counter")
      .Value = .Value + 1
    End With
	ActiveDocument.PrintOut Copies:=1
End With
End Sub

Now I modified my "EventClassModule" to automatically call this sub when printing:

Private Sub App_DocumentBeforePrint(ByVal Doc As Document, Cancel As Boolean)

	Cancel = True

	Call FilePrint
	ActiveDocument.Saved = False
	If ActiveDocument.Saved = False Then ActiveDocument.Save

End Sub

Method 2:

You need to create a module inside word and a txt file containing the current incremental number.

I like to call the txt file the document name and store in the same location.

I am working on automating this process (see Method 1!) (See


Sub SerialNumber()
' SerialNumber Macro
Dim Message  As String, Title  As String, Default  As String, NumCopies  As Long
 Dim Rng1   As Range

 ' Set prompt.
Message = "Enter the number of copies that you want to print"
 ' Set title.
Title = "Print"
 ' Set default.
Default = "1"

' Display message, title, and default value.
Dim SerialNumber As String
NumCopies = Val(InputBox(Message, Title, Default))
 SerialNumber = System.PrivateProfileString("W:\settings.txt", _
 "MacroSettings", "SerialNumber")

 If SerialNumber = "" Then
     SerialNumber = 1
 End If

 Set Rng1 = ActiveDocument.Bookmarks("SerialNumber").Range
 Counter = 0

 While Counter < NumCopies
     Rng1.Text = SerialNumber
     SerialNumber = SerialNumber + 1
     Counter = Counter + 1



Inside Word Document where you want to place the Serial Number:

Insert >> Bookmark >> "SerialNumber" >> Add



  • No labels