Run time Error 4608 when print document via VBA

Ian Price
Ian Price used Ask the Experts™
on
Hi Experts,

Wondering is someone could help me out.

We normally send word doc to the printer via a VBA macro so I can control which tray we use in the printer \ copier.

I picked up a ticket from a user - some document which came from practical law just will not print.

I get a  Run time Error 4608

1x.png
If I clear all the formatting it will work
Code below but basically just a recorded macro
 FirstPageTray = wdPrinterLowerBin
 OtherPagesTray = wdPrinterLowerBin
being the important part as sets tray three on our hp printer

I must stress the code works on 99% of doc but there is something funky about this document

This is the code
Sub CPSE_Plain()

'
' CPSE_Plain Macro
'
'
    Selection.WholeStory
    With ActiveDocument.Styles(wdStyleNormal).Font
        If .NameFarEast = .NameAscii Then
            .NameAscii = ""
        End If
        .NameFarEast = ""
    End With
    ActiveDocument.Content.Orientation = wdTextOrientationHorizontal
    With ActiveDocument.PageSetup
        .LineNumbering.Active = False
        .Orientation = wdOrientPortrait
        .TopMargin = InchesToPoints(1)
        .BottomMargin = InchesToPoints(1)
        .LeftMargin = InchesToPoints(1.25)
        .RightMargin = InchesToPoints(1.25)
        .Gutter = InchesToPoints(0)
        .HeaderDistance = InchesToPoints(0.5)
        .FooterDistance = InchesToPoints(0.5)
        .PageWidth = InchesToPoints(8.27)
        .PageHeight = InchesToPoints(11.69)
        .FirstPageTray = wdPrinterLowerBin
        .OtherPagesTray = wdPrinterLowerBin
        .SectionStart = wdSectionNewPage
        .OddAndEvenPagesHeaderFooter = False
        .DifferentFirstPageHeaderFooter = True
        .VerticalAlignment = wdAlignVerticalTop
        .SuppressEndnotes = False
        .MirrorMargins = False
        .TwoPagesOnOne = False
        .BookFoldPrinting = False
        .BookFoldRevPrinting = False
        .BookFoldPrintingSheets = 1
        .GutterPos = wdGutterPosLeft
        .SetAsTemplateDefault
    End With
    Application.PrintOut FileName:="", Range:=wdPrintAllDocument, Item:= _
        wdPrintDocumentWithMarkup, Copies:=1, Pages:="", PageType:= _
        wdPrintAllPages, Collate:=True, Background:=True, PrintToFile:=False, _
        PrintZoomColumn:=0, PrintZoomRow:=0, PrintZoomPaperWidth:=0, _
        PrintZoomPaperHeight:=0
End Sub
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
ste5anSenior Developer

Commented:
In this case, you should add line numbers and an error handler to get the troubling property.

But you should also check, whether the printer setup on that users machine is working correctly and whether he used the correct printer.
Maybe you should consider setting the printer also in code, but this requires a uniform printer setup on all used client machines,
Ian PriceIT Manager

Author

Commented:
Hi ste5an "In this case, you should add line numbers and an error handler to get the troubling property." Could you elaborate?

Printer setup on the machine is correct I can replicate the error on other machnes

Thanks
Ian.
Senior Developer
Commented:
E.g.

Option Explicit

Public Sub CPSE_Plain()

    On Local Error GoTo LocalError

10  Selection.WholeStory
11  If ActiveDocument.Styles(wdStyleNormal).Font.NameFarEast = ActiveDocument.Styles(wdStyleNormal).Font.NameAscii Then
12    ActiveDocument.Styles(wdStyleNormal).Font.NameAscii = ""
13  End If

14  ActiveDocument.Styles(wdStyleNormal).Font.NameFarEast = ""
15  ActiveDocument.Content.Orientation = wdTextOrientationHorizontal
16  ActiveDocument.PageSetup.LineNumbering.Active = False
17  ActiveDocument.PageSetup.Orientation = wdOrientPortrait
18  ActiveDocument.PageSetup.TopMargin = InchesToPoints(1)
19  ActiveDocument.PageSetup.BottomMargin = InchesToPoints(1)
20  ActiveDocument.PageSetup.LeftMargin = InchesToPoints(1.25)
21  ActiveDocument.PageSetup.RightMargin = InchesToPoints(1.25)
22  ActiveDocument.PageSetup.Gutter = InchesToPoints(0)
23  ActiveDocument.PageSetup.HeaderDistance = InchesToPoints(0.5)
24  ActiveDocument.PageSetup.FooterDistance = InchesToPoints(0.5)
25  ActiveDocument.PageSetup.PageWidth = InchesToPoints(8.27)
26  ActiveDocument.PageSetup.PageHeight = InchesToPoints(11.69)
27  ActiveDocument.PageSetup.FirstPageTray = wdPrinterLowerBin
28  ActiveDocument.PageSetup.OtherPagesTray = wdPrinterLowerBin
29  ActiveDocument.PageSetup.SectionStart = wdSectionNewPage
30  ActiveDocument.PageSetup.OddAndEvenPagesHeaderFooter = False
31  ActiveDocument.PageSetup.DifferentFirstPageHeaderFooter = True
32  ActiveDocument.PageSetup.VerticalAlignment = wdAlignVerticalTop
33  ActiveDocument.PageSetup.SuppressEndnotes = False
34  ActiveDocument.PageSetup.MirrorMargins = False
35  ActiveDocument.PageSetup.TwoPagesOnOne = False
36  ActiveDocument.PageSetup.BookFoldPrinting = False
37  ActiveDocument.PageSetup.BookFoldRevPrinting = False
38  ActiveDocument.PageSetup.BookFoldPrintingSheets = 1
39  ActiveDocument.PageSetup.GutterPos = wdGutterPosLeft
40  ActiveDocument.PageSetup.SetAsTemplateDefault
41  Application.PrintOut FileName:="", Range:=wdPrintAllDocument, Item:= wdPrintDocumentWithMarkup, Copies:=1, Pages:="", PageType:= wdPrintAllPages, Collate:=True, Background:=True, PrintToFile:=False, PrintZoomColumn:=0, PrintZoomRow:=0, PrintZoomPaperWidth:=0, PrintZoomPaperHeight:=0
    Exit Sub  

LocalError:
  MsgBox "Error " & Err.Number & " in line " & Erl() &": & Err.Description, vbCritical + vbOkOnly

End Sub

Open in new window


p.s. please use the CODE button or [code[/code] tags to embed code into your posts. This increases readability and makes copying code simpler. Also edit your old posts to embed it.
Ian PriceIT Manager

Author

Commented:
Perfect thank you

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial