Results 1 to 2 of 2

Thread: Print VBA cancel command not working

  1. #1
    Junior Member
    Join Date
    Oct 2012
    Posts
    26
    Rep Power
    0

    Print VBA cancel command not working

    Hi all,

    I use the following code to print a worksheet.

    Code:
    Private Sub CommandButton3_Click()
    If Application.Dialogs(xlDialogPrinterSetup).Show = False Then Exit Sub
    Sheets("INPUT WV").PrintOut
    End Sub
    I can cancel the dialogprintersetup without any error. But when i try to cancel e.g. the pdf save as dialog when i choose a pdf printer it gives me a runtime error and point to the Sheets("INPUT WV").PrintOut. When i save the pdf everything is just fine.

    Regards,

  2. #2
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,401
    Rep Power
    10
    That's because you are not going ahead with the print, and cancelling it after you select the printer. I'd just put in an

    Code:
    On Error Resume Next
    statement before that line
    A dream is not something you see when you are asleep, but something you strive for when you are awake.

    It's usually a bad idea to say that something can't be done.

    The difference between dream and aim, is that one requires soundless sleep to see and the other requires sleepless efforts to achieve

    Join us at Facebook

Similar Threads

  1. Replies: 2
    Last Post: 04-17-2013, 11:53 PM
  2. Print Nth Worksheet To Mth Worksheet using VBA
    By Ryan_Bernal in forum Excel Help
    Replies: 2
    Last Post: 02-28-2013, 06:57 PM
  3. VBA - Split command
    By Rasm in forum Excel Help
    Replies: 1
    Last Post: 09-15-2012, 06:26 AM
  4. Replies: 7
    Last Post: 08-08-2012, 10:24 AM
  5. Print Selective Area
    By r_know in forum Excel Help
    Replies: 2
    Last Post: 06-21-2012, 11:09 PM

Posting Permissions

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