+ Reply to Thread
Results 1 to 3 of 3

Print or PrintPreview

  1. #1
    Forum Contributor
    Join Date
    01-21-2005
    Location
    Colorado
    MS-Off Ver
    2000,2003,2007
    Posts
    481

    Print or PrintPreview

    Is there a way to determine if the user has selected 'Print' or 'PrintPreview' in
    order to end up in the Workbook_BeforePrint subroutine? I'd like to know at
    the start of the Workbook_BeforePrint subroutine so that I can take
    appropriate steps for either situation. Up to this point I can only tell if the
    got there from a 'Print' or 'PrintPreview' selection at the conclusion of any
    code within the Workbook_BeforePrint subroutine.

    Thanks for any advice.

  2. #2
    Forum Contributor
    Join Date
    01-24-2007
    Location
    Southampton, UK
    Posts
    137
    To my knowledge you cannot tell whether the user selected print preview or just print in the BeforePrint event.

    However, a way round this is to ask the user again whether they want to preview & print or just print at the beginning of the BeforePrint event - a little annoying for the user perhaps, but if your code depends on knowing which has been selected then it's important.

    The following outlines how to get the answer from the user....

    Private Sub Workbook_BeforePrint(Cancel As Boolean)
    On Error GoTo EXIT_ROUTINE
    Application.EnableEvents = False
    Select Case MsgBox("Do you wish to preview before printing?" & vbCrLf & vbCrLf & "[Click 'Yes' to Preview, 'No' to Print without preview, or 'Cancel']", vbYesNoCancel)
    Case vbYes ' preview & print
    ActiveSheet.PrintPreview
    '.....other lines of code prior to preview & print
    GoTo PRINT_OUT
    Case vbNo ' print only
    PRINT_OUT:
    '.....lines of code prior to printing
    ActiveSheet.PrintOut
    Case vbCancel ' no preview or print
    GoTo EXIT_ROUTINE
    End Select
    '.....any other code lines after preview/print
    EXIT_ROUTINE:
    Cancel = True
    Application.EnableEvents = True
    End Sub

  3. #3
    Forum Contributor
    Join Date
    01-21-2005
    Location
    Colorado
    MS-Off Ver
    2000,2003,2007
    Posts
    481
    Thanks for the suggestion.

    I did find another workaround that requires less user intervention but is not
    completely fool proof.

    I reassigned the OnAction events of the 'Print' and 'PrintPreview' buttons on the "Standard" and "Worksheet Menu Bar" CommandBars.
    I also reassign these buttons to have no OnAction events when the user disables the current workbook or changes to a different
    workbook using the workbook event handlers.

    As I said, this does not deal with if the user clicks print from within the PrintPreview view or from within the PageSetup dialog.
    However possibly a combination of my button OnAction reassignment and Loz's code a the beginning of the BeforePrint subroutine would be more robust.

    Has anyone else tried to deal with this problem?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1