In Event printer fails
In the code you use earlier in the procedure you can find the answer to your question. The 'On Error Resume Next' statement says to just skip over any errors. So when it tries to assign the Sheet name to a name that may not exist, it would just skip that error. Then the programmer who wrote that code had errors turned back on with the statement 'On Error GoTo 0'. So you can precede and proceed any code you expect to have an error with those statements
For example
On Error Resume Nex
sh.Range("PRGM").PrintOu
On Error GoTo
You might want to evaluate the error code however, so you can notify your user that there was a printing problem. But since we ignored errors earlier in the procedure, we need to clear (the Err object's Clear method) the Err, so we can evaluate properly. Consider these changes
On Error Resume Nex
Err.Clea
sh.Range("PRGM").PrintOu
If Err.Number < 0 Then msgbox "There was an error printing.
On Error GoTo
I hope that helps
-Bra
----- Graham wrote: ----
I have a procedure detailed below which was created, thanks to support fro
this group, to remove highlighted areas from worksheets before printing a
area and then after printing to return the sheet to the areas highlighted a
before. This works fine but there is a problem which can occur in tw
situations. If the procedure is activated (from a button ) when a printer i
not connected or if a printer error occurs during printing (which doe
happen on some network printers), then the sheet is left with the area
without the highlights. ie the line to restore the highlights is after th
print command as you will see. Is there a way to error trap for this type o
situation? I as always value any help or guidance
Sub printmargins(
Dim myRng As Rang
Dim myColorIndex As Lon
Dim sh As Workshee
For Each sh In ThisWorkbook.Worksheet
If sh.Range("C2").Value 0 The
Set myRng = Nothin
On Error Resume Nex
Set myRng = sh.Range(sh.Name
On Error GoTo
If myRng Is Nothing The
'do nothing, it didn't have a range with the worksheet nam
Els
myColorIndex = myRng(1).Interior.ColorInde
myRng.Interior.ColorIndex = xlNon
With sh.PageSetu
.Orientation = xlPortrai
.FitToPagesWide =
.FitToPagesTall =
.LeftMargin = Application.InchesToPoints(0.551181102362205
.RightMargin = Application.InchesToPoints(0.15748031496063
End Wit
sh.Range("PRGM").PrintOu
myRng.Interior.ColorIndex = myColorInde
End I
End I
Next s
End Su
Kind regards
Graham Haugh
Turriff, Scotlan
|