PDA

View Full Version : how to run when print is cancelled



leematty
08-27-2007, 08:42 PM
This little bit of code i am using to display the print box to select the printer before printing, however i need some if statement or the like so when cancel is selected on the print box, that the code doesnt crash and just returns to the page. can anyone please assist.


Private Sub CommandButton11_Click()

Application.Dialogs(xlDialogPrinterSetup).Show
Sheets("Investments Output").Select
Sheets("Investments Output").Activate
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True

End Sub

anandbohra
08-27-2007, 11:11 PM
try this one

Private Sub CommandButton1_Click()
Dim a
a = MsgBox("This will Print required report" & vbCrLf & "are you sure to Print", vbYesNo, "Your Name")
If a = vbYes Then
Call Print_Report
MsgBox "Pl Collect the Printouts from default Printer", vbInformation, "Your Name"
Else
MsgBox "Print Cancelled", vbCritical, "Your Name"
End If
End Sub




then in module paste this code for print_report

Sub Print_Report()
Sheets(Array("Investments Output", "Investments Input")).Select
Sheets("Investments Output").Activate
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
End Sub

leematty
08-27-2007, 11:17 PM
thanks i'll try this

Bob Phillips
08-28-2007, 12:33 AM
Private Sub CommandButton11_Click()

If Application.Dialogs(xlDialogPrinterSetup).Show Then
Sheets("Investments Output").Select
Sheets("Investments Output").Activate
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
End If

End Sub