Link to home
Start Free TrialLog in
Avatar of c_foster
c_foster

asked on

Adding a sequential "Order number" to a one page MS Word form

I'm in the process of preparing a one-page order form for a charitable drive.  I would like to include a sequential "order number" to the one page form that would increment with each page i print.  This way i can ask particpants to include the order number on the memo line of their checks and be able to match the checks to the order form to ensure delivery of the proper product.  

I found the SEQ information in MS Word 2007, however, on the 5 test pages i printed, they all came out with an order number of 1 instead of 1 on the first printed page, 2 on the second printed page, etc.  

Does anyone know if this is possible? And if so, how?

Maximum points because i need this fast.  

Thank you,
Carolyn
Avatar of Rartemass
Rartemass
Flag of Australia image

You would need a script for this.
The below should get you started. It assumes document is one page long, has one section and one footer type.
It increments the page number. If you want it to increase beyond 100, change that value to the highest number you want.

<pre>Public Sub PrintDocumentWithIncrementingPageNumbers()
Dim n As Long
With ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary).PageNumbers
'Increment page number:
For n = 1 To 100
.StartingNumber = n
ActiveDocument.PrintOut
Next 'n
End With
End Sub
</pre>

Open in new window


Do you need to save this number so that the next time it prints the number is the same?
You could also use a template with a macro for this that when a new document is created from it, the number increases. This link should aid with that:
http://word.mvps.org/FAQs/MacrosVBA/NumberDocs.htm
ASKER CERTIFIED SOLUTION
Avatar of Rartemass
Rartemass
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You could use a document property, a document property field (DocProperty) and this macro set.

Option Explicit

Sub FilePrint()
    Dim dlg As Dialog
    Set dlg = Dialogs(wdDialogFilePrint)
    If dlg.Display = -1 Then
        dlg.Execute
        SetOrderNo
    End If
End Sub

Sub FilePrintDefault()
    ActiveDocument.PrintOut
    SetOrderNo
End Sub

Sub SetOrderNo()
    Dim prop As DocumentProperty
    For Each prop In ActiveDocument.CustomDocumentProperties
        If prop.Name = "OrderNo" Then
            prop.Value = prop.Value + 1
            Exit For
        End If
    Next prop
    If prop Is Nothing Then
        Set prop = ActiveDocument.CustomDocumentProperties.Add("OrderNo", False, msoPropertyTypeNumber, 1)
    End If
    ActiveDocument.Fields.Update
End Sub

Open in new window


The code updates
Avatar of c_foster
c_foster

ASKER

This is the simplest solution.
Thank you