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
留意如果成功打印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
With CommonDialog1
.ShowPrinter
End With
Exit Sub
errPrint:
Unload Me
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
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