Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word 2007

Status
Not open for further replies.

jparham

Technical User
Oct 17, 2009
1
GB
I am trying to create a voucher in word 2007 on this voucher i want a box with a number in it. now i only have one page what I would like this number to do is when I print the page but print say 10 of this page I would like this number to increase by one each time with out creating a 100 separate pages the same, but with different numbers in the box i.e. page one has the voucher with 0001 in the box then page 2 has 0002 in the box. is it possible to do this with out creating all 100 pages. Thank you for listening to my dribble
 
One way or another you have to send 100 different pages to the printer. Assuming you don't know the language your printer speaks (PCL perhaps), you can either create a single 100 page document and print it, or you can create 100 single-page documents and print them individually (you don't need to save them). Without running some tests I don't know which would be 'better'. Either would work with much the same sort of code loop; To create 100 single page print jobs, you would need something along the lines of:

open document
For n = 1 to 100
populate text box with n
print
Next n
close document discarding changes

Bookmarks can be a bit fiddly sometimes but having the position of the number marked with a bookmark would probably allow for the easiest code, along the lines of (untested)

Code:
Documents.Open [i]your_document[/i]
For n = 1 to 100
    With ActiveDocument
        .Bookmarks("[i]your_bookmark[/i].Range.text = format(n, "0000")
        .PrintOut BackGround:=False
        .Undo
    End With
Next
Activedocument.close wddonotsavechanges

Enjoy,
Tony

------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

I'm working (slowly) on my own website
 
You can insert a header with a simple page number - it self-increments by one for each new page. Can't find out how to format it with the leading zeroes though, which is easily done in earlier versions. MS Access is great at this - any chance you can create an Access report as a solution?

Cogito eggo sum – I think, therefore I am a waffle.
 
Hi genomon,

jparham doesn't want to end up with a 100-page document, just a single-paged document which increments and prints a counter for each printing of that page.


Cheers
[MS MVP - Word]
 
This does that.

A blank bookmark ("counter"). In my test the last paragraph is:

Printed copy: [blank text bookmark named "counter"]
Code:
Option Explicit

Sub UpdateBookmark(strBM As String, strText As String)
Dim r As Range
With ActiveDocument
  Set r = .Bookmarks(strBM).Range
  r.Text = strText
  .Bookmarks.Add strBM, r
End With
Set r = Nothing
End Sub

Sub PrintIncrement()
Dim j As Long
For j = 1 To 10
   Call UpdateBookmark("counter", Format(j, "0000"))
   ActiveDocument.PrintOut
Next
' make bookmark blank again
Call UpdateBookmark("counter", "")
End Sub
Executing PrintIncrement - and I only tested 1 to 10, as I did not want to print 100! - does:

1. changes the bookmark to "0001" and prints the page
2. changes the bookmark to "0002" and prints the page
3. changes the bookmark to "0003" and prints the page
4. changes the bookmark to "0004" and prints the page
5. changes the bookmark to "0005" and prints the page
etc.

and finally ends up making the text of "counter" blank again.

So, 10 printed copies of a single page document, but with a counter as part of the printing.

There are of course other ways to do this.

"A little piece of heaven
without that awkward dying part."

advertisment for Reese's Peanut Butter Cups (a chocolate/peanut butter confection)

Gerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top