Results 1 to 6 of 6
  1. #1
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Doing something at print time (WinNT/W97)

    Could anyone tell me, please, how to tell Word to do something when a document is sent to print, along the lines of Sub document_open to run when the document is opened?

    I've tried the object browser, VBA help and the MSKB but I don't seem to be able to think of keywords that will give me any sort of useful return.

    Any help would be greatly appreciated!
    Beryl M


  2. #2
    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: Doing something at print time (WinNT/W97)

    Are you in a position to create a Sub FilePrint() to intercept the print command? You then have total control over what happens when the user wants to print. For example:

    <pre>Sub FilePrintDefault()
    Call myFilePrint
    End Sub

    Sub FilePrint()
    Call myFilePrint
    End Sub

    Sub myFilePrint()
    With Dialogs(wdDialogFilePrint)
    If .Display() <> -1 Then
    'user cancel
    Exit Sub
    Else
    MsgBox "Your print job is under my command."
    'inspect or change user options here
    If .Range = wdPrintAllDocument Then
    MsgBox "You kill so many trees!! No, not today."
    If Selection.Type = wdSelectionIP Then
    .Range = wdPrintCurrentPage
    'next line for debug only to show changes
    If .Display() = 0 Then Exit Sub
    Else
    .Range = wdPrintFromTo
    .from = 1
    .to = 1
    'next line for debug only to show changes
    If .Display() = 0 Then Exit Sub
    End If
    .Execute
    Else
    .Execute
    End If
    End If
    End With
    End Sub</pre>

    The properties for the dialog are: Background, AppendPrFile, Range, PrToFileName, From, To, Type, NumCopies, Pages, Order, PrintToFile, Collate, FileName, Printer, OutputPrinter, DuplexPrint, PrintZoomColumn, PrintZoomRow, PrintZoomPaperWidth, PrintZoomPaperHeight. They are documented, more or less, under the PrintOut method.

    Hope this helps.

  3. #3
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Doing something at print time (WinNT/W97)

    Hi Jscher, thanks for the input. I *think* this would do what is wanted - what we have is a template that has to be printed on special paper, and they want me to put a msgbox saying 'remember to use special paper' in that would come up when they send the document based on this template to print. If I put a version of your code in 'this document' for the template, it would do that, wouldn't it?

    By the way, would this work whichever way they send it to print, ie File, Print, or the print button on the toolbar, or Ctrl-P, etc?

    Many thanks for your help <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>
    Beryl M


  4. #4
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Doing something at print time (WinNT/W97)

    Jscher, I've now had a chance to try your suggestion and whilst it works, do you know if it's possible to have something run (like the message box mentioned) when print is chosen, then carry on with the normal print function afterwards? Alternatively, do you know where I can find a copy of the code that runs the print function so I can pull it into my template in its entirety and just add my msgbox in at the appropriate point?

    For that matter, the answer to the second question above would be of great interest generally, not just for this question ... <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

    Once again, many thanks
    Beryl M


  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: Doing something at print time (WinNT/W97)

    You could make this change:

    <pre>Sub myPrint()
    If MsgBox("You did put that special paper in the printer, right?", _
    vbQuestion + vbYesNo) <> vbYes Then Exit Sub
    Dialogs(wdDialogFilePrint).Show
    End Sub</pre>


  6. #6
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Doing something at print time (WinNT/W97)

    <img src=/S/grin.gif border=0 alt=grin width=15 height=15> You, sir, are brilliant! <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16> I was just thinking "but how do I get the print button etc to refer to myPrint", when I thought I'd try putting your code direct into FilePrint and FilePrintDefault - and it worked! All the print functions worked out of the dialog by referring to the 'master' and everything's hunky dory.

    Many thanks!
    Beryl M


Posting Permissions

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