Error on printing

G

Graham Haughs

I have the procedure set out below where there may be the situation where a
printer is not connected or there is an error with the printer.

Sub printsummarybudget()
With Worksheets("SumBud").PageSetup
.CenterHorizontally = True
.Orientation = xlPortrait
.FitToPagesWide = 1
.FitToPagesTall = 1
End With
On Error Resume Next
Err.Clear
Worksheets("SumBud").Range("Sumbud").PrintOut Copies:=1, Preview:=False,
Collate:=True
If Err.Number <> 0 Then MsgBox "There was an error printing or there is no
printer attached", vbExclamation, "Printer Problem"
On Error GoTo 0
End Sub

The problem is when I start the procedure I get a window with the Printer
Set-up option of selecting which printer I want to use. It is connected to a
network so there is a choice of printer. However if I am not connected and I
choose the Cancel option on the printer selection window I get a run-time
error 1004 "Unable to set the CentreHorizontally property of the Page Set up
Class." I would value any guidance on how to sort this situation. I
basically don't want any errors appearing if someone clicks the print
procedure when there are no printers attached. The above worked fine if
there was only one printer option but not now.

Kind Regards,
Graham Haughs
Turriff, Scotland
 
J

Jorge Rodrigues

Hi, Graham,
Try this way:
Sub printsummarybudget()
With Worksheets("Sheet1").PageSetup
On Error GoTo EndMacro

.CenterHorizontally = True
.Orientation = xlPortrait
.FitToPagesWide = 1
.FitToPagesTall = 1
End With
Err.Clear
Worksheets("Sheet1").Range("A1:B10").PrintOut Copies:=1, Preview:=False,
Collate:=True
EndMacro:

If Err.Number <> 0 Then MsgBox "There was an error printing or there is no
printer attached", vbExclamation, "Printer Problem"
On Error GoTo 0
End Sub

Regards.
Jorge
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top