Results 1 to 8 of 8
  1. #1
    New Lounger
    Join Date
    Sep 2003
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    printing macro (officew xp (word))

    Hi,
    I wonder if anyone could write a macro that achieves the following.

    Count number of pages in open doc.

    List in a form or other display the page number and
    have a box for how many copies of that page to be printed.
    Select printer
    print.

    The objective is to open say a 25 page document and on one form decide to print say 5 copies of page 4, six copies of page 5, two copies of page 11 etc etc

    Hope that all makes sense.

    thanks
    cobwebs

  2. #2
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: printing macro (officew xp (word))

    Yes, it can be done but why? This task doesn't sound particularly useful other than as a VBA exercise and would be time consuming to create from scratch.

    I suggest you track down Macros8.dot which comes with Word 97 on the installation disk. It has a macro called SuperDocStatistics that will introduce you to ways of performing this task. The actual code to do your task should cater for each section of the document in the same way the SuperDoc form can review each section's properties. This will give you ideas on the interface you should be working with too.

    As a trap for young players - selecting the printer after selecting the pages is going to lead to heartache as the document will repaginate according to the selected printer. You also need to define each page to print with a section & page notation to ensure you get the expected pages.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  3. #3
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: printing macro (officew xp (word))

    Oh, but really you need a thumbnail print preview on the dialog. Otherwise, how do you know which page you really want to print? <img src=/S/laugh.gif border=0 alt=laugh width=15 height=15>

    I wonder if you might be able to add a drop-down control to the Print Preview toolbar to run a macro to print the current page the number of times selected by the user in the drop-down. In the past I've been able to trigger a macro that way, but the trick is to avoid the Preview view closing after each print. Fun stuff!!

  4. #4
    New Lounger
    Join Date
    Sep 2003
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: printing macro (officew xp (word))

    Hi,
    Thank you for your comments. I seem to have avoided word 97 in my travels ... at least no longer have any installation disks for it! There is a reason, and it is this. I run courses and the handouts are in word files. Not everybody takes all the handouts and i end up with uneven numbers of spares. Preparing for the next course I need to make the handouts back up to whatever number of participants there are on the course. Preview not required as page1=handout 1 etc... Hope that clarifies. Regards
    Cobwebs

  5. #5
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: printing macro (officew xp (word))

    Okay, I see. Here's the problem. Dialog boxes are only so big, and while it is possible to write code to add lots of little texboxes to a dialog, it's hard work if the number is variable and can be more than what would commonly be considered a reasonable number (more like 7 than 25). So while this is not as pretty, it might work better for you:

    <pre>Sub PrintAllOnePageAtATime()
    ' Confirm printer selection with the user
    If MsgBox("Use this printer?" & vbCrLf & vbCrLf & Application.ActivePrinter, _
    vbExclamation + vbYesNo) = vbNo Then
    MsgBox "Open File|Print, change the printer, click Close, and try again.", _
    vbInformation
    Exit Sub
    End If
    ' Set up variables
    Dim intCounter As Integer, intCopies As Integer
    With ActiveDocument
    ' Loop using physical page numbers; does not work with renumbered pages
    For intCounter = 1 To .ComputeStatistics(wdStatisticPages)
    intCopies = CInt(InputBox("How many copies of page " & _
    intCounter & " do you want?", "Print Page by Page", 0))
    If intCopies > 0 Then
    .PrintOut Range:=wdPrintRangeOfPages, _
    Pages:="p" & intCounter, Copies:=intCopies
    End If
    Next
    End With
    End Sub</pre>

    Note that this was tested in Word 2002 printing to the pdfFactory print driver (didn't want to kill trees for the sake of testing). I assume it will work with a regular printer, but if there are any problems, please report back.

    There is a very important limitation to this macro! If your document contains multiple sections with restarted page numbering anywhere in them, the macro will not know which page to print. The .PrintOut method works the same as the print dialog in this regard. Changing the above code to address that is beyond the scope of my current schedule, sorry.

  6. #6
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: printing macro (officew xp (word))

    For reasons that I can't explain, when you copy the code from the Lounge directly into a text editor, the lines wrap in a bad way.

    Try pasting first into the body of a Word document. There will be a pause while Word thinks about it, but it should preserve the wrapping.

    Then copy and paste that into the VBE.

  7. #7
    New Lounger
    Join Date
    Sep 2003
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: printing macro (officew xp (word))

    Hi,
    I am very grateful. I initially had a problem...until i realised how to copy the code correctly..(excuse me..I'm a little dim here)... but sorted that and got it to work. I have tried it with the printer offline and certainly it appears to put the right pages into the printer queue... which i then deleted to save the trees also. To all purposes then the problem appears solved. Many thanks for your time in doing this for me.

    Very best wishes

    Cobwebs
    :-)
    cobwebs

  8. #8
    New Lounger
    Join Date
    Sep 2003
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: printing macro (officew xp (word))

    Hi
    I discovered that! One long line... and i realised that the underscore _ was a line continuation.. once that was sorted i copied it into notepad... and edited it to match the look in the lounge window... and it worked well. Many thanks
    cobwebs

Posting Permissions

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