Results 1 to 10 of 10
  1. #1
    New Lounger
    Join Date
    Nov 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Logbook pagination: There has got to be a better way...

    We use MS Word to create pages for the several types of log books we are required to keep. We have a Word document for each logbook that has a single page with a page number in the footer.

    We have a macro that we run that asks how many pages we want (usually 200), increments the page number and prints that page until the requested number of pages are printed.

    We use a PDF printer that creates a PostScript file. The problem we are seeing is that the first dozen pages are queued - you can see them in the printer queue - then the remaining pages are apparently sent directly to the PS file, and THEN the first dozen pages are printed.

    When that PS file is converted to PDF, the first dozen pages are at the end of the PDF, instead of at the front where they belong.

    I've tried spooling with immediate printing, and with delayed printing, and not spooling at all. Nothing seems to change the outcome.

    Here are the ways I've thought of attacking this problem:

    --Is there a way to have word do this automatically without creating a 200 page doc and without the macro sending one page at a time to the printer?

    --Is there a way to force the pages to ALL go directly to the PS file instead of piling up the first 12 in the queue?

    --Is there a way to expand the queue to hold all 200 pages so they'll get processed IN ORDER?

    --Alternatively could the macro, instead of printing each page, append these pages together into a single large document and then print that? How would that be done in VBA?

    Thanks in advance!

  2. #2
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,853
    Thanks
    4
    Thanked 259 Times in 239 Posts
    Yes it can be done very easily using VBA. Can you post the code you are using currently?

    Wouldn't it be more staightforward to avoid macros and just create documents of each logbook variant (with say 500 pages) and then the user can determine how many pages they want printed?
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  3. #3
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,055
    Thanks
    2
    Thanked 417 Times in 346 Posts
    The problem with out-of-order pages is a by-product of background printing. The simple fix is to disallow it, via:
    .PrintOut Background:=False

    For the multi-page generation approach, see: http://www.msofficeforums.com/word-v...numbering.html
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  4. #4
    New Lounger
    Join Date
    Nov 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Andrew,
    Andrew,

    Having the logbook docs contain 500 pages, and re-paginating at the required starting number would be a way to do it. But occasionally the format of the page change and that change would have to be cascaded to all the pages.

    Mabe an alternative approach might be to have the macro take the one page doc, copy it as a separate document object, duplicate the pages X number of times, number the pages in that ONE doument, then send that ONE document to the PDF printer.

    Here is the code we are currently using:

    Sub paginate()
    '
    ' paginate Macro
    ' Macro created 11/17/2005 by DM
    '
    Dim Message As String, Title As String, Default As String, NumCopies As Long
    Dim Rng1 As Range
    Dim strPrinter As String
    Dim strOutput As String

    strOutput = "C:\Documents and Settings\dm\" + ActiveDocument.Name + ".ps"
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set a = fs.CreateTextFile(strOutput, True)
    a.Close

    ' Set prompt.
    Message = "Enter the number of copies that you want to print"
    ' Set title.
    Title = "Print"
    ' Set default.
    Default = "1"

    ' Display message, title, and default value.
    NumCopies = Val(InputBox(Message, Title, Default))

    'Get the starting page number from "Settings.txt"
    SerialNumber = System.PrivateProfileString("C:\Settings.Txt", _
    "MacroSettings", "SerialNumber")

    If SerialNumber = "" Then
    SerialNumber = 1
    End If

    'Find the current page number, bookmarked as "SerialNumber"
    Set Rng1 = ActiveDocument.Bookmarks("SerialNumber").Range
    Counter = 0

    'cache the current printer name and Switch to the PDF printer
    strPrinter = Application.ActivePrinter
    Application.ActivePrinter = "Adobe PDF3"

    'Generate the pages, printing each to the PDF printer
    While Counter < NumCopies
    Rng1.Delete
    'Rng1.Text = SerialNumber
    Rng1.Text = Format(SerialNumber, "0000#")
    ActiveDocument.PrintOut True, True, wdPrintCurrentPage, strOutput
    SerialNumber = SerialNumber + 1
    Counter = Counter + 1
    Wend

    'set the default prionter back to where it was before
    Application.ActivePrinter = strPrinter

    'Save the next page number back to the Settings.txt file ready for the next use.
    'NOTE: This is not neccessary since the same settings.txt is used for all logs,
    'and the numbers differ so it is always changed before running anyway.
    System.PrivateProfileString("C:\Settings.txt", "MacroSettings", _
    "SerialNumber") = SerialNumber

    'Recreate the bookmark ready for the next use.
    'This IS reqired so the current page number in the doc is bookmarked for use the next time the macro runs.
    With ActiveDocument.Bookmarks
    .Add Name:="SerialNumber", Range:=Rng1
    End With

    End Sub


    I have no idea why they use a separate txt file to store the serial number since it is used for all the log books and has to be reset anyway, I'd just assume grab it the same way the page count it taken with an input box.

    Here is the settings.txt file:
    [MacroSettings]
    SerialNumber=30801


    Thanks
    Last edited by Thanbor; 2012-11-15 at 12:20.

  5. #5
    New Lounger
    Join Date
    Nov 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks Macropod!
    Setting the background printing to false resolved the problem.

    And thanks for that link. That discussion looks interesting.

    Dunno if I'll have the time to overhaul all the logbooks to do it that way, but at least the pages are in order now usign the current macro.

  6. #6
    New Lounger
    Join Date
    Nov 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    One other question:

    The macro works flawlessly now on our XP machines. But we have a Windows 7 machine that the code crashes on the ActiveDocument.PrintOut command. The odd thing is that it WILL execute and print several pages, then crash with a runtime error 5142.

    Then in debug, if you try to re-execute it just repeats the error. But if you move the pointer up one command to the
    Rng1.Text = Format(SerialNumber, "0000#") command then resume, it will print several more pages before crashing with another 5142 error.

    I know the code is right, AND the PDF printer driver is working or it would not execute at all. If I just reset the execution pointer every time it crashes, eventually you get all the pages into the postscript file and it does create a PDF with all pages in the correct order.

    So why does it crash every 3 - 5 pages?

    I was thinking it might be a timing thing where the code is trying to execute another printout before the last one is done because the Win7 machine is running so much faster than the XP machines. I tried putting in a delay (a counting loop) of up to 7 seconds between the Rng1.text and the ActiveDocument.PrintOut, but that did not work either.

    I can put the Rng1.text and ActiveDocument.PrintOut into a separate function and trap for the error, and just re-execute the function til it DOES execute without error.

    Any other suggestions or ideas?

  7. #7
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,055
    Thanks
    2
    Thanked 417 Times in 346 Posts
    The error may be due to a fault in your Office or print driver installation on the Win 7 machines.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  8. #8
    New Lounger
    Join Date
    Nov 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Tried reinstalling Adobe Acrobat 9 - no dice. Tried PDF Creator from SourceForge instead of Adobe, but got the same error:

    MacroCrash.jpg

  9. #9
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,055
    Thanks
    2
    Thanked 417 Times in 346 Posts
    Try inserting a 'DoEvents' line after your 'ActiveDocument.PrintOut' line. That should allow Word to do whatever housekeeping it needs as each loop is processed.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  10. #10
    New Lounger
    Join Date
    Nov 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    That worked! We are good to go. Thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •