Dear Experts
I have a VBA to preview before printing.
My requirement is to display the message box over the print preview not after closing the preview.
When I select Yes, preview screen should disappear and Print
When I select No, preview screen should disappear and go to the selected sheet.
Thank you in advance.
I have a VBA to preview before printing.
My requirement is to display the message box over the print preview not after closing the preview.
When I select Yes, preview screen should disappear and Print
When I select No, preview screen should disappear and go to the selected sheet.
Thank you in advance.
VBA Code:
Sub PrintChq()
Dim ans As Boolean
Dim answer As Integer
'
' PrintChq Macro
Dim strOldPrinter As String
strOldPrinter = Application.ActivePrinter
Application.ScreenUpdating = False
Sheets("Sheet2").Select
ActiveSheet.PrintPreview
answer = MsgBox("Yes / No", vbQuestion + vbYesNo + vbDefaultButton2, "Continue Printing Cheque ?")
If answer = vbYes Then
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True, ActivePrinter:="HP LaserJet Professional P1102"
Application.ActivePrinter = strOldPrinter
Sheets("Sheet1").Select
Application.ScreenUpdating = True
Else
MsgBox "Print Cheque Cancelled"
End If
End Sub