Printing books

S

Stephen Yale

I have read how to print booklets from the following website:

http://www.mvps.org/word/FAQs/Formatting/BookletPrinting.htm

A book is made up of signatures. (Lots of booklets glued and stitched
together)

If I have a book that is 100 pages long and I want to print 5 signatures
(booklets) each containing 20 pages can the code be adjusted so that when I
want to print signatures, It will prompt me for the signature size and then
print all the signatures maintaining the original page numbering.

Using the original code I will get 50 pages (printed on both sides) and the
first page would have pages 1,2 - 99,100 2nd page 3,4 - 97,98 etc

I want to get the first signature to print (1st page) 1,2 - 19,20 (2nd page)
3,4 - 17,18 etc
2nd signature would be (1st page) 21,22 - 39,40 (2nd page) 23,24 - 37,38 etc

If I have not made this clear let me know.

Stephen
 
D

Doug Robbins - Word MVP

Hi Stephen,

I guess that by the original code, you mean that at
http://www.mvps.org/word/FAQs/MacrosVBA/BookletMacro.htm. Modifications to
that would be necessary to print the document in five parts in the way in
which you want.

If might be easier to split the document into five separate documents and
format the page numbers to start at the required number.

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 
D

Doug Robbins - Word MVP

Hi Stephen,

It's getting too late at night for me to get my mind around how to make this
completely dynamic as far a variations in Total Pages/Number of Signatures
are concerned, but I think the following GetPagesToPrintDuplex subroutine
will handle the 100 page/5 signature setup that you first mentioned.

Sub GetPagesToPrintDuplex()
Totalpages = InputBox("Enter the Total Number of Pages")
numsignatures = InputBox("Enter the number of signatures")
numpages = Totalpages / numsignatures
For PageNum = 1 To numpages / 2
If Len(PagestoPrint) > 0 Then PagestoPrint = PagestoPrint & ","
If PageNum Mod 2 = 1 Then
'odd page
PagestoPrint = PagestoPrint & (numpages + 1 - PageNum) & ","
& PageNum
PagestoPrint2 = PagestoPrint2 & (numpages * 2 + 1 - PageNum)
& "," & PageNum + numpages & ","
PagestoPrint3 = PagestoPrint3 & (numpages * 3 + 1 - PageNum)
& "," & PageNum + numpages * 2 & ","
PagestoPrint4 = PagestoPrint4 & (numpages * 4 + 1 - PageNum)
& "," & PageNum + numpages * 3 & ","
PagestoPrint5 = PagestoPrint5 & (numpages * 5 + 1 - PageNum)
& "," & PageNum + numpages * 4 & ","
Else
' even page
PagestoPrint = PagestoPrint & PageNum & "," & (numpages +
1 - PageNum)
PagestoPrint2 = PagestoPrint2 & PageNum + numpages & "," &
(numpages * 2 + 1 - PageNum) & ","
PagestoPrint3 = PagestoPrint3 & PageNum + numpages * 2 & ","
& (numpages * 3 + 1 - PageNum) & ","
PagestoPrint4 = PagestoPrint4 & PageNum + numpages * 3 & ","
& (numpages * 4 + 1 - PageNum) & ","
PagestoPrint5 = PagestoPrint5 & PageNum + numpages * 4 & ","
& (numpages * 5 + 1 - PageNum) & ","
End If
Next PageNum
PagestoPrint = PagestoPrint & ", " & PagestoPrint2 & PagestoPrint3 &
PagestoPrint4 & Left(PagestoPrint5, Len(PagestoPrint5) - 1)
' MsgBox PagestoPrint
End Sub


--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 
S

Stephen

Hi Doug, I have managed to achieve my goal as follows:

I use a form to collect amount of pages per signatue ( I check for Mod
4 of this value to ensure the booklet has the correct amount of pages
) as follows:

Private Sub cmdOK_Click()

If fCheckPages Then

If Me.optDuplex Then
Call Booklet2000DuplexPrinter(txtintSigNum)
Else
Call Booklet2000SimplexPrinter(txtintSigNum)
End If
Unload Me

Else

Call UserForm_Initialize

End If

End Sub


Private Sub UserForm_Initialize()

Me.optDuplex = True
Me.optSimplex = False
Me.txtintSigNum = 20

End Sub

Private Function fCheckPages() As Boolean

fCheckPages = False

If Me.txtintSigNum Mod 4 > 0 Then 'Not divisible by 4
MsgBox "You must enter a number that is divisible by 4 for the
amount of pages per signature." & vbCrLf & vbCrLf & _
"Word will automatically add blank pages at the end of the
document " & _
"to cope with an uneven amount of pages within the
document", vbExclamation, "Signature Error"
fCheckPages = False
Else
fCheckPages = True
End If

End Function

The code for printing the booklet signatures follows:

Option Explicit

Dim intSigNum As Integer, intSigNumDone As Integer, intI As Integer
Dim PageNum As Long, NumPages As Long, XtraPages As Long
Dim MyRange As Range
Dim PagestoPrint As String, OddPagesToPrint As String,
EvenPagesToPrint As String

Sub Booklet2000DuplexPrinter(intSigNumPages As Integer)

NumPages = Selection.Information(wdNumberOfPagesInDocument)

'If number of pages not a multiple of number of signature pages,
add manual page breaks at the end
If NumPages Mod intSigNumPages > 0 Then Call
AddExtraPages(intSigNumPages)
intSigNum = NumPages / intSigNumPages

'loop through the signatures
For intI = 1 To intSigNum

'Put the pages to be printed into a single string, in the correct
order
Call GetPagesToPrintDuplex(intSigNumPages)
'Print
Call PrintPages(PagestoPrint)
'clear pages to print variable
PagestoPrint = vbNullString
'increment the pages to print by last amount printed
intSigNumDone = intSigNumDone + intSigNumPages

Next intI

'If any page breaks were added, delete them again
If XtraPages > 0 Then Call DeleteExtraPages
Call ClearVariables

End Sub

Sub Booklet2000SimplexPrinter(intSigNumPages As Integer)

NumPages = Selection.Information(wdNumberOfPagesInDocument)
'If number of pages not a multiple of number of signature pages,
add manual page breaks at the end
If NumPages Mod intSigNumPages > 0 Then Call
AddExtraPages(intSigNumPages)
intSigNum = NumPages / intSigNumPages

'loop through the signatures
For intI = 1 To intSigNum

'Put the pages to be printed into a single string, in the correct
order
Call GetPagesToPrintSimplex(intSigNumPages)
Call PrintPages(OddPagesToPrint)
'clear pages to print variable
PagestoPrint = vbNullString
'increment the pages to print by last amount printed
intSigNumDone = intSigNumDone + intSigNumPages

Next intI

MsgBox "Please turn the paper over and press OK when you're ready
to print"

For intI = 1 To intSigNum

'Put the pages to be printed into a single string, in the correct
order
Call GetPagesToPrintSimplex(intSigNumPages)
Call PrintPages(EvenPagesToPrint)
'clear pages to print variable
PagestoPrint = vbNullString
'increment the pages to print by last amount printed
intSigNumDone = intSigNumDone + intSigNumPages

Next intI

'If any page breaks were added, delete them again
If XtraPages > 0 Then Call DeleteExtraPages
Call ClearVariables

End Sub

Sub AddExtraPages(intSigNumPages)
'Adds page breaks to make the number of pages a multiple of 4
XtraPages = intSigNumPages - NumPages Mod intSigNumPages
For PageNum = 1 To XtraPages
Set MyRange = ActiveDocument.Range
MyRange.Collapse wdCollapseEnd
MyRange.InsertBreak Type:=wdPageBreak
Next PageNum
NumPages = Selection.Information(wdNumberOfPagesInDocument)
End Sub

Sub GetPagesToPrintDuplex(intSigNumPages As Integer)
For PageNum = 1 To intSigNumPages / 2
If Len(PagestoPrint) > 0 Then PagestoPrint = PagestoPrint & ","
If PageNum Mod 2 = 1 Then
'odd page
PagestoPrint = PagestoPrint & (intSigNumPages + intSigNumDone +
1 - PageNum) & "," & PageNum + intSigNumDone
Else
' even page
PagestoPrint = PagestoPrint & PageNum + intSigNumDone & "," &
(intSigNumPages + intSigNumDone + 1 - PageNum)
End If
Next PageNum
End Sub

Sub GetPagesToPrintSimplex(intSigNumPages As Integer)
For PageNum = 1 To NumPages / 2
If PageNum Mod 2 = 1 Then
'odd page
If Len(OddPagesToPrint) > 0 Then OddPagesToPrint =
OddPagesToPrint & ","
OddPagesToPrint = OddPagesToPrint & (NumPages + 1 - PageNum) &
"," & PageNum
Else
'even page
If Len(EvenPagesToPrint) > 0 Then EvenPagesToPrint =
EvenPagesToPrint & ","
EvenPagesToPrint = EvenPagesToPrint & PageNum & "," & (NumPages
+ 1 - PageNum)
End If
Next PageNum
End Sub

Sub PrintPages(PagestoPrint As String)
Dim Pos As Long, PagesToPrintChunk As String, TestPages As Variant
'The 'pages to print' string can only be a maximum of 256
characters long
'(Word limitation). If > 256 characters, prints it in smaller
chunks
'(otherwise just prints it)
Do While Len(PagestoPrint) > 256
PagesToPrintChunk = Left$(PagestoPrint, 256)
'Strip the chunk string so it ends before the final comma
Pos = InStrRev(PagesToPrintChunk, ",")
PagesToPrintChunk = Left$(PagesToPrintChunk, Pos - 1)
'find out how many pages are now listed in the string (needs to
be a multiple of 4)
TestPages = Split(PagesToPrintChunk, ",")
NumPages = UBound(TestPages) + 1
'If not a multipke of 4, removes some page numbers so that it is
If NumPages Mod 4 > 0 Then
For PageNum = 1 To NumPages Mod 4
Pos = InStrRev(PagesToPrintChunk, ",")
PagesToPrintChunk = Left$(PagesToPrintChunk, Pos - 1)
Next
End If

Application.PrintOut Pages:=PagesToPrintChunk, _
Range:=wdPrintRangeOfPages, Background:=False
'Strip main string so it starts just after the same comma
PagestoPrint = Mid$(PagestoPrint, Pos + 1)
Loop

Application.PrintOut Pages:=PagestoPrint, _
Range:=wdPrintRangeOfPages, Background:=False
End Sub

Sub DeleteExtraPages()
'If manual page breaks were added earlier, deletes them again
Set MyRange = ActiveDocument.Range
MyRange.Collapse wdCollapseEnd
MyRange.MoveStart unit:=wdCharacter, Count:=-(XtraPages + 1)
MyRange.Delete
End Sub

Sub ClearVariables()
Set MyRange = Nothing
PageNum = 0
NumPages = 0
XtraPages = 0
intSigNum = 0
intSigNumDone = 0
PagestoPrint = vbNullString
OddPagesToPrint = vbNullString
EvenPagesToPrint = vbNullString
End Sub

Thanks for your help though...

Stephen
 
S

Stephen

Hi Doug
I have completed the vba codig for signature printing. The last post
may have had incorrect code for the simplex routine. I only tested the
duplex at work :-(

Here is the module code:

Option Explicit

Dim intSigNum As Integer, intSigNumDone As Integer, intI As Integer
Dim PageNum As Long, NumPages As Long, XtraPages As Long
Dim MyRange As Range
Dim PagestoPrint As String, OddPagesToPrint As String,
EvenPagesToPrint As String

Sub Booklet2000DuplexPrinter(intSigNumPages As Integer)

NumPages = Selection.Information(wdNumberOfPagesInDocument)

'If number of pages not a multiple of number of signature pages,
add manual page breaks at the end
If NumPages Mod intSigNumPages > 0 Then Call
AddExtraPages(intSigNumPages)
intSigNum = NumPages / intSigNumPages

'loop through the signatures
For intI = 1 To intSigNum

'Put the pages to be printed into a single string, in the correct
order
Call GetPagesToPrintDuplex(intSigNumPages)
'Print
Call PrintPages(PagestoPrint)
'clear pages to print variable
PagestoPrint = vbNullString
'increment the pages to print by last amount printed
intSigNumDone = intSigNumDone + intSigNumPages

Next intI

'If any page breaks were added, delete them again
If XtraPages > 0 Then Call DeleteExtraPages
Call ClearVariables

End Sub

Sub Booklet2000SimplexPrinter(intSigNumPages As Integer)

NumPages = Selection.Information(wdNumberOfPagesInDocument)
'If number of pages not a multiple of number of signature pages,
add manual page breaks at the end
If NumPages Mod intSigNumPages > 0 Then Call
AddExtraPages(intSigNumPages)
intSigNum = NumPages / intSigNumPages

'loop through the signatures
For intI = 1 To intSigNum

'Put the pages to be printed into a single string, in the correct
order
Call GetPagesToPrintSimplex(intSigNumPages)
Call PrintPages(OddPagesToPrint)
MsgBox "Please turn the paper over and press OK when you're ready
to print"
Call PrintPages(EvenPagesToPrint)
'clear pages to print variable
PagestoPrint = vbNullString
'increment the pages to print by last amount printed
intSigNumDone = intSigNumDone + intSigNumPages

Next intI

'If any page breaks were added, delete them again
If XtraPages > 0 Then Call DeleteExtraPages
Call ClearVariables

End Sub

Sub AddExtraPages(intSigNumPages)
'Adds page breaks to make the number of pages a multiple of
signature pages
XtraPages = intSigNumPages - NumPages Mod intSigNumPages
For PageNum = 1 To XtraPages
Set MyRange = ActiveDocument.Range
MyRange.Collapse wdCollapseEnd
MyRange.InsertBreak Type:=wdPageBreak
Next PageNum
NumPages = Selection.Information(wdNumberOfPagesInDocument)
End Sub

Sub GetPagesToPrintDuplex(intSigNumPages As Integer)
For PageNum = 1 To intSigNumPages / 2
If Len(PagestoPrint) > 0 Then PagestoPrint = PagestoPrint & ","
If PageNum Mod 2 = 1 Then
'odd page
PagestoPrint = PagestoPrint & (intSigNumPages + intSigNumDone +
1 - PageNum) & "," & PageNum + intSigNumDone
Else
' even page
PagestoPrint = PagestoPrint & PageNum + intSigNumDone & "," &
(intSigNumPages + intSigNumDone + 1 - PageNum)
End If
Next PageNum
End Sub

Sub GetPagesToPrintSimplex(intSigNumPages As Integer)
For PageNum = 1 To intSigNumPages / 2
If PageNum Mod 2 = 1 Then
If Len(OddPagesToPrint) > 0 Then OddPagesToPrint = OddPagesToPrint
& ","
OddPagesToPrint = OddPagesToPrint & (intSigNumPages +
intSigNumDone + 1 - PageNum) & "," & PageNum + intSigNumDone
Else
If Len(EvenPagesToPrint) > 0 Then EvenPagesToPrint =
EvenPagesToPrint & ","
EvenPagesToPrint = EvenPagesToPrint & PageNum + intSigNumDone &
"," & (intSigNumPages + intSigNumDone + 1 - PageNum)
End If
Next PageNum
End Sub

Sub PrintPages(PagestoPrint As String)
Dim Pos As Long, PagesToPrintChunk As String, TestPages As Variant
'The 'pages to print' string can only be a maximum of 256
characters long
'(Word limitation). If > 256 characters, prints it in smaller
chunks
'(otherwise just prints it)
Do While Len(PagestoPrint) > 256
PagesToPrintChunk = Left$(PagestoPrint, 256)
'Strip the chunk string so it ends before the final comma
Pos = InStrRev(PagesToPrintChunk, ",")
PagesToPrintChunk = Left$(PagesToPrintChunk, Pos - 1)
'find out how many pages are now listed in the string (needs to
be a multiple of 4)
TestPages = Split(PagesToPrintChunk, ",")
NumPages = UBound(TestPages) + 1
'If not a multipke of 4, removes some page numbers so that it is
If NumPages Mod 4 > 0 Then
For PageNum = 1 To NumPages Mod 4
Pos = InStrRev(PagesToPrintChunk, ",")
PagesToPrintChunk = Left$(PagesToPrintChunk, Pos - 1)
Next
End If
Debug.Print "Pages:=" & PagesToPrintChunk, "Range:=" &
wdPrintRangeOfPages

'Application.PrintOut Pages:=PagesToPrintChunk, _
Range:=wdPrintRangeOfPages, Background:=False
'Strip main string so it starts just after the same comma
PagestoPrint = Mid$(PagestoPrint, Pos + 1)
Loop
Debug.Print "Pages:=" & PagestoPrint, "Range:=" &
wdPrintRangeOfPages

'Application.PrintOut Pages:=PagestoPrint, _
Range:=wdPrintRangeOfPages, Background:=False
End Sub

Sub DeleteExtraPages()
'If manual page breaks were added earlier, deletes them again
Set MyRange = ActiveDocument.Range
MyRange.Collapse wdCollapseEnd
MyRange.MoveStart unit:=wdCharacter, Count:=-(XtraPages + 1)
MyRange.Delete
End Sub

Sub ClearVariables()
Set MyRange = Nothing
PageNum = 0
NumPages = 0
XtraPages = 0
intSigNum = 0
intSigNumDone = 0
PagestoPrint = vbNullString
OddPagesToPrint = vbNullString
EvenPagesToPrint = vbNullString
End Sub

I have a form that asks the user "How many pages per signature
(divisble by 4) and select the Duplex/Siplex from a radio option
button. I call the form from a sub attached to the command bar. Here
is the form code I use to call the print routines:

Private Sub cmdOK_Click()

If fCheckPages Then

If Me.optDuplex Then
Call Booklet2000DuplexPrinter(txtintSigNum)
Else
Call Booklet2000SimplexPrinter(txtintSigNum)
End If
Unload Me

Else

Call UserForm_Initialize

End If

End Sub


Private Sub UserForm_Initialize()

Me.optDuplex = True
Me.optSimplex = False
Me.txtintSigNum = 20

End Sub

Private Function fCheckPages() As Boolean

fCheckPages = False

If Me.txtintSigNum Mod 4 > 0 Then 'Not divisible by 4
MsgBox "You must enter a number that is divisible by 4 for the
amount of pages per signature." & vbCrLf & vbCrLf & _
"Word will automatically add blank pages at the end of the
document " & _
"to cope with an uneven amount of pages within the
document", vbExclamation, "Signature Error"
fCheckPages = False
Else
fCheckPages = True
End If

End Function




 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top