Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-02-2015, 01:26 PM
BruceM BruceM is offline Two-sided printing with sequential numbering Windows 7 64bit Two-sided printing with sequential numbering Office 2010 32bit
Advanced Beginner
Two-sided printing with sequential numbering
 
Join Date: Feb 2015
Posts: 41
BruceM is on a distinguished road
Default Two-sided printing with sequential numbering

I am trying to use the code here to sequentially number multiple copies of a one-page document, with a twist. Rather than adding the code to every document to be numbered, I wanted to add the code to an add-in. To that end, I have the following code:


Code:
 
Public Sub PageSeqNum()
'---------------------------------------------------------------------------------------
' Procedure : PageSeqNum
' Author    : BruceM, from code by Doug Robbins at word.mvps.org
' Date      : 27-Feb-2015
' Purpose   : Prints a single page the number of times specified, with pages _
                sequentially numbered in "Page x of y" format
' Comments  : Works on a single page document only
'---------------------------------------------------------------------------------------
  Const msgPgNum As String = _
    "Enter the number of copies you want to print"
  Const ttlPgNum As String = _
    "Print Copies"
  Const strDefault As String = _
    "1"
  Const strBkMk As String = _
    "PageNum"
    
  Dim lngNum        As Long     ' Number of copies to be printed (from input box)
  Dim lngCur        As Long     ' Number of current page
  Dim rngBkMk       As Range    ' The Range of the SeqNumber bookmark
  Dim strPrinter    As String   ' The name of the active printer
 
On Error GoTo PageSeqNum_Error
 
  strPrinter = _
    ActivePrinter
 
' Set the printer for duplex printing
  SetPrinterDuplex _
    PrinterName:=strPrinter, _
    DuplexSetting:=2              ' More on this in the thread
 
  Set rngBkMk = _
    ActiveDocument.Bookmarks(strBkMk).Range
  lngNum = _
    Val(InputBox(msgPgNum, ttlPgNum, strDefault))
  lngCur = _
    1
 
  While lngCur <= lngNum
    With rngBkMk
      .Delete
      .Text = "Page " & lngCur & " of " & lngNum
    End With
    ActiveDocument.PrintOut
    lngCur = _
      lngCur + 1
  Wend
 
ProcExit: 
' Re-create the bookmark for next time
  ActiveDocument.Bookmarks.Add _
    Name:=strBkMk, _
    Range:=rngBkMk
    
' Reset the printer duplex setting to its original (lngOldDuplex is set within SetPrinterDuplex _
  when it is called at the beginning of this procedure)
  SetPrinterDuplex _
    PrinterName:=strPrinter, _
    DuplexSetting:=lngOldDuplex
  
  Exit Sub
PageSeqNum_Error:
  MsgBox "Error " & Err.Number & " (" & Err.Description & ") " & _
         "in PageSeqNum, basPrintPages"
  Resume ProcExit
  
End Sub
Regarding the duplex setting, that is an attempt to set the printer to duplex printing using code from here (kb 230743). Duplex is needed because this system is used to print things such as maintenance logs that are bound into books. The printer supports duplex.

The general idea is that I insert a bookmark named PageNum into the footer of the document to be sequentially numbered, then run the PageSeqNum code via a ribbon icon (that is, run the macro that is in the add-in, in a way that is simple to do).

The code for sequential numbering works well enough, except I cannot find a way to make it print on both sides of the page, even when I set the printer to duplex as its default setting and/or set two-sided printing for the document.

Brief comment about the code to set duplex: The plan is to detect the original settings (typically one-sided, but not always), and restore that setting at the end. I haven't worked out the details yet, and I may have some questions about that later, but for now I am just trying to solve the basic problem of two-sided printing for this situation. It makes no difference if I omit the procedure calls from the code posted above.

If this cannot be made to work we will revert to the old system of copying the original one-page document and paste to a new page, then copy the whole document (two pages now) and paste four more times (ten total), and then the whole thing again ten times to arrive at a hundred pages (the typical number that needs to be printed). Something like that.

I have been fighting with this all day, and the work day is almost over. I should have posted sooner, but I mention this now so as not to seem rude if there is a delay before I respond to any suggestions.
Reply With Quote
  #2  
Old 03-04-2015, 05:34 AM
BruceM BruceM is offline Two-sided printing with sequential numbering Windows 7 64bit Two-sided printing with sequential numbering Office 2010 32bit
Advanced Beginner
Two-sided printing with sequential numbering
 
Join Date: Feb 2015
Posts: 41
BruceM is on a distinguished road
Default

I now believe that what I am trying to do is not possible, but can anybody confirm that?
Reply With Quote
  #3  
Old 03-04-2015, 04:04 PM
Guessed's Avatar
Guessed Guessed is offline Two-sided printing with sequential numbering Windows 7 32bit Two-sided printing with sequential numbering Office 2010 32bit
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

I believe you will need two pages if you want to get double-sided out of the printer. You could send 50 copies of a two page document as a more elegant way of getting 100 impressions.

Also, I would use content controls to hold the page x of y information as the coding will be far simpler. Aircode of the concept might be along these lines

Code:
lngNum = Val(InputBox(msgPgNum, ttlPgNum, strDefault))
For lngCur = 1 to lngNum Step 2
  ActiveDocument.ContentControls(1).Range.Text = lngCur & " of " & lngNum
  ActiveDocument.ContentControls(2).Range.Text = lngCur + 1 & " of " & lngNum
Next lngCur
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #4  
Old 03-05-2015, 10:37 AM
BruceM BruceM is offline Two-sided printing with sequential numbering Windows 7 64bit Two-sided printing with sequential numbering Office 2010 32bit
Advanced Beginner
Two-sided printing with sequential numbering
 
Join Date: Feb 2015
Posts: 41
BruceM is on a distinguished road
Default

Andrew, thanks for the reply. I haven't tested extensively yet, but it appears a version of your suggestion will work.

I stayed with bookmarks since they are far easier for users to set up. I'll go with more complex coding and a simpler user interaction every time.

The process is to copy a one page document, go to the end of the document, and paste to create two identical pages (this is for a sequentially numbered maintenance log book). Then add a section break between the pages, and break the link to the first section in the second section footer. Add bookmarks PageNum1 and PageNum2 to the two footers, then run the macro. The macro is in an Add-In, so I will be sure the user has the Add-In, and add an icon to the Home tab to run the macro.

As I mentioned, I am staying with bookmarks, but within that context I am using the For...Step method you outlined, which together with the two-page document seems to solve the problem. I am also using code to switch to duplex printing, then back to the original setting, via a call to another procedure.

So, thanks again. The two-page idea was the piece I couldn't see.
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Two-sided printing with sequential numbering How do I do a Sequential Numbering? gburya Word VBA 26 07-04-2017 03:29 PM
Formatting single sided thesis with indented tables for double sided printing Akshara Word 1 05-01-2014 01:29 PM
Two-sided printing with sequential numbering Sequential page numbering im_rusahbh Word VBA 1 12-23-2013 05:28 PM
Printing Double Sided Cards 4/page HELP PLEASE! C.J. Word 5 03-27-2012 07:29 AM
Two-sided printing with sequential numbering Sequential Numbering jdwoods Word VBA 7 12-16-2011 05:11 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:28 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft