Word - Page Numbers based on print copies?

Kiloelectronvolt

Board Regular
Joined
Oct 5, 2015
Messages
81
Office Version
  1. 365
Platform
  1. Windows
Hi All,

I tried asking on microsoft forums, and I'm banging my head against a wall. I have a microsoft word question maybe you guys know how to answer.


We bought a thermal printer that prints off of a roll. (Endless stickers.) If we tell word to print 7 copies, it will print off 7 stickers. (7 pages)


Word asks "# of copies" in the print screen, and I type how many I need for that run. This example, being 7 copies or pages.


So, I would love the first sticker/page to say 1 of 7. The 2nd sticker will come off saying 2 of 7. Until all 7 pages are printed. Basically indicating we printed 7 copies. The final will say 7 of 7. Almost like page numbers, but for # of copies instead. I want this automated based on how many we print each session though.



So, if John's order has 7 pieces, I would print 7 copies and it would say 1 of 7, 2 of 7, etc.

And if Steve's order has 3 pieces, I would print 3 copies, and it would say 1 of 3, 2 of 3, and 3 of 3.
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Not being a Word expert but also having never heard of a feature like this being available in Word, I might wonder if there is a way to do it through your printer...

ABE: No doubt VBA will also be able to pull this off of you're open to that.
 
Upvote 0
Not being a Word expert but also having never heard of a feature like this being available in Word, I might wonder if there is a way to do it through your printer...

ABE: No doubt VBA will also be able to pull this off of you're open to that.
Hi Jon!

I've found a few vba codes that do half of what I'm looking for but I'm a total novice with vba to make it produce both variables X of Y pages.

I'm of course open to the idea!
 
Upvote 0
Can you post the code(s) that you're referring to?
 
Upvote 0
Link -- this is one, but this one remembers from one job to the next and I don't need that feature. I'd like every print job t restart the counter
 
Upvote 0
Really just guessing here, but I've added a line that I suspect will ensure the variable is reset. As written now, it looks to me like it's only resetting to 0 if the variable hasn't been initialized yet and if it's remaining initialized from one run to the next, it's not getting reset to 0.

Does this work?

VBA Code:
Public Sub PrintNumberedCopies()
    Dim varItem As Variable
    Dim bExists As Boolean
    Dim lCopiesToPrint As Long
    Dim lCounter As Long
    Dim lCopyNumFrom As Long

    ' ensure our doc variable exists
    bExists = False
    For Each varItem In ActiveDocument.Variables
        If varItem.Name = "CopyNum" Then
            bExists = True
            Exit For
        End If
    Next varItem

    ' initialize document variable if doesn't exist
    If Not bExists Then
        ActiveDocument.Variables.Add _
            Name:="CopyNum", Value:=0
    End If
    
    'ensure variable is always reset to 0
    ActiveDocument.Variables("CopyNum") = 0

    ' ask how many to print
    lCopiesToPrint = InputBox( _
        Prompt:="How many copies?", _
        Title:="Print And Number Copies", _
        Default:="1")

    ' ask where to start numbering
    lCopyNumFrom = CLng(InputBox( _
        Prompt:="Number at which to start numbering copies?", _
        Title:="Print And Number Copies", _
        Default:=CStr(ActiveDocument.Variables("CopyNum") + 1)))

    ' loop through the print-write-print cycle
    For lCounter = 0 To lCopiesToPrint - 1
        ' update the document variable
        ActiveDocument.Variables("CopyNum") = _
            lCopyNumFrom + lCounter
        ' print this numbered copy
        ActiveDocument.PrintOut Copies:=1
    Next lCounter
End Sub
 
Upvote 0
Well. I feel dumb. I tried adding the docvariable fields and I just simply don't know what I'm doing. It prints the number of copies, but not with any text on it.

Would you be able to upload your word document that I can try?
 
Upvote 0
I don't have a Word document I am trying this in. I would guess you are only getting a number, though, because that is all that is written out to have.

VBA Code:
Public Sub PrintNumberedCopies()
    Dim wDoc as Word.Document
    Dim varItem As Variable
    Dim bExists As Boolean
    Dim lCopiesToPrint As Long
    Dim lCounter As Long
    Dim lCopyNumFrom As Long

    ' set current doc to variable
    Set wDoc = ActiveDocument
    
    ' ensure doc number variable exists
    bExists = False
    For Each varItem In wDoc.Variables
        If varItem.Name = "CopyNum" Then
            bExists = True
            Exit For
        End If
    Next varItem

    ' initialize document variable if doesn't exist
    If Not bExists Then
        wDoc.Variables.Add _
            Name:="CopyNum", Value:=0
    End If
    
    ' ensure variable is always reset to 0
    wDoc.Variables("CopyNum") = 0
    
    ' ensure doc total variable exists
    bExists = False
    For Each varItem In wDoc.Variables
        If varItem.Name = "CopyTotal" Then
            bExists = True
            Exit For
        End If
    Next varItem

    ' initialize document variable if doesn't exist
    If Not bExists Then
        wDoc.Variables.Add _
            Name:="CopyTotal", Value:=0
    End If
    
    ' ensure variable is always reset to 0
    wDoc.Variables("CopyTotal") = 0    

    ' ask how many to print
    lCopiesToPrint = InputBox( _
        Prompt:="How many copies?", _
        Title:="Print And Number Copies", _
        Default:="1")

    ' ask where to start numbering
    lCopyNumFrom = CLng(InputBox( _
        Prompt:="Number at which to start numbering copies?", _
        Title:="Print And Number Copies", _
        Default:=CStr(wDoc.Variables("CopyNum") + 1)))

    wDoc.Variables("CopyTotal") = lCopiesToPrint
    
    ' loop through the print-write-print cycle
    For lCounter = 0 To lCopiesToPrint - 1
        ' update the document variable
        wDoc.Variables("CopyNum") = _
            lCopyNumFrom + lCounter
        ' print this numbered copy
        wDoc.PrintOut Copies:=1
    Next lCounter
    
    ' reset variables on document
    With wDoc
        .Variables("CopyNum") = 0
        .Variables("CopyTotal") = 0
    End With
End Sub

Then in your document, you'll need that extra field, so something like this (remember you need to enter these with Ctrl+F9):

Code:
{ DOCVARIABLE "CopyNum" } of { DOCVARIABLE "CopyTotal" }
 
Upvote 0
{ DOCVARIABLE "CopyNum" } of { DOCVARIABLE "CopyTotal" }
Hi! I did all that, but then it just prints the pages blank. I used the CTRL f9. After I print, they disappear off the page (may be normal for1 time use?)
 
Upvote 0
So I gave this a try...

First thing I noticed is that the field codes as typed aren't what you get when you put them in through the insert menu (specifically, there are no quotes that way). So try the field codes like this:

Code:
{ DOCVARIABLE CopyNum \* MERGEFORMAT } of { DOCVARIABLE CopyTotal \* MERGEFORMAT }

Next, I noticed that nothing was updating. I found two ways to address this. One would be to add code that tells the fields to update. The option I went with, though, was to change a setting in the Word menu. Instructions on this are here: Update fields

You want to check the box by Update fields before printing so that Word automatically updates the field values in the document right before sending to the printer.

With these changes, I got it to work. I will note one thing, though I don't think this matters, and that is that I was printing to PDF to not waste paper. I think you will get the same results printing to a real printer.
 
Upvote 0
Solution

Forum statistics

Threads
1,215,089
Messages
6,123,058
Members
449,091
Latest member
ikke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top