我用application调用了打印,但是遇到一个问题,就是如果用户点击了取消的话,我不知道怎么退出程序,一般的可以定义取消健使其退出,但这个是windows的,无法定义,
如何实现点击确定,程序向下执行
点击取消,程序直接退出帮帮我吧,一定给分!

解决方案 »

  1.   

    On Error GoTo errPrint
        
        With CommonDialog1
            .ShowPrinter
        End With
        
        Exit Sub
        
    errPrint:
        Unload Me
      

  2.   

    我用的是VBA啊,在Excel里面有CommonDialog
      

  3.   

    在excel里面有commondialog么?我调用了出错啊。
      

  4.   

    On Error GoTo printerr
        Application.EnableCancelKey = xlErrorHandler
        Application.Dialogs(xlDialogPrint).Show
        If ActiveSheet Is ThisWorkbook.Sheets("main") Then
            Sheet2.PrintOut
        Else
            Sheet1.PrintOut
        End If
    Exit Sub
    printerr:
        MsgBox ("error")
    End Sub
      

  5.   

    '调用Excel内部文件打印对话框,不用加程序处理.Dialogs(wdDialogFilePrint).Show
      

  6.   

    上面是我重新写的代码,没用VB的commondialog,用的VBA的东西,但调用出打印机,按cancel键之后仍然不会跳到printerr去,而是继续执行下面的代码,这是为什么?
      

  7.   

    留意如果成功打印MsgBox Application.Dialogs(xlDialogPrint).Show会返回一个True值。
    On Error GoTo printerr
        Application.EnableCancelKey = xlErrorHandler
        if Application.Dialogs(xlDialogPrint).Show=false then exit sub
        If ActiveSheet Is ThisWorkbook.Sheets("main") Then
            Sheet2.PrintOut
        Else
            Sheet1.PrintOut
        End If
    Exit Sub
    printerr:
        MsgBox ("error")
    End Sub