View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Asking user to print and error message

Sub PrintInvoice()
Dim Res As Long
Res = MsgBox("Do you want to print the invoice?", vbQuestion +
vbYesNo)
Select Case Res
Case vbYes
On Error Resume Next
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
if err.Number < 0 then _
MsgBox "Error: " & err.Description, vbOK + vbInformation
Err.clear
On Error goto 0
Case vbNo
Exit Sub
End Select
End Sub

Since you don't offer any choices, your msgbox should just show vbOK

--
Regards,
Tom Ogilvy


"Olly" wrote in message
om...
I am trying to crate some code that asks the user if they want to
print and if the computer encounters an error because there is no
printer installed. How can I adapt my code bellow to allow this to
happen?

Sub PrintInvoice()
Dim Res As Long
Res = MsgBox("Do you want to print the invoice?", vbQuestion +
vbYesNo)
Select Case Res
Case vbYes
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Dim Res As Error
Cas Error("1004")
MsgBox "Error: No print has been found on your
system", vbOKCancel + vbInformation
Case vbNo
Exit Sub
End Select
End Sub

Thanks
Olly