J
Jeremiah
I have two separate macros working together in Word
2003. The first (LetterheadBond) inserts a continuous
section break at the top of the document's second page.
The second (PrintFinal) checks the user's ActivePrinter
and sets the print trays accordingly. After printing, it
is supposed to return the trays to the user's default
setting.
Problem is, PrintFinal generates an error message when it
tries to reset the trays. If I run that code without
running LetterheadBond first, it goes fine. But after
splitting the document into sections, PrintFinal
complains...
Run-time error '4608':
Value out of range
....when I tell it...
ActiveDocument.PageSetup.FirstPageTray =
wdPrinterDefaultBin
Why is this? Is there something I can do to get VBA to
change the entire documents' tray settings at once? My
code follows. I've added astericks where the error
occurs.
I know my code is something of an eyesore, but thanks for
any help.
******************************
Sub FormatLetterheadBond()
' Format the first page
Selection.HomeKey Unit:=wdStory
With Selection.PageSetup
.TopMargin = InchesToPoints(1.8)
.BottomMargin = InchesToPoints(1)
.LeftMargin = InchesToPoints(1.9)
.RightMargin = InchesToPoints(1)
End With
' If there is a second page...
If ActiveDocument.BuiltInDocumentProperties
(wdPropertyPages) > 1 Then
' ...Then jump to second page
Application.Browser.Next
' If the second page is not an envelope...
If Selection.PageSetup.PaperSize <>
wdPaperEnvelope10 Then
' ...Then insert a section break
Selection.InsertBreak
Type:=wdSectionBreakContinuous
' Format the remaining pages
With Selection.PageSetup
.TopMargin = InchesToPoints(1)
.BottomMargin = InchesToPoints(1)
.LeftMargin = InchesToPoints(1)
.RightMargin = InchesToPoints(1)
End With
End If
End If
End Sub
----------------------------
Sub PrintFinal()
' Get the printer
Dim Printer As String
Printer = UCase(Application.ActivePrinter)
' Set the first page to letterhead (based on printer)
Selection.HomeKey Unit:=wdStory
With Selection.PageSetup
' LaserJet 4
If InStr(Printer, "\\SBSERVER\ANNEX HP4 PLUS") >
0 Then
.FirstPageTray = wdPrinterLowerBin
.OtherPagesTray = wdPrinterUpperBin
End If
' LaserJet 4200
If InStr(Printer, "\\SBSERVER\HP LASERJET 4200")
.OtherPagesTray = 1262
End If
End With
' If there is a second page...
If ActiveDocument.BuiltInDocumentProperties
(wdPropertyPages) > 1 Then
' ...Then jump to second page
Application.Browser.Next
' If the second page is not an envelope...
If Selection.PageSetup.PaperSize <>
wdPaperEnvelope10 Then
' ...Then set the second and subsequent pages to
bond (based on printer)
With Selection.PageSetup
' LaserJet 4
If InStr(Printer, "\\SBSERVER\ANNEX HP4
PLUS") > 0 Then
.FirstPageTray = wdPrinterUpperBin
.OtherPagesTray = wdPrinterUpperBin
End If
' LaserJet 4200
If InStr(Printer, "\\SBSERVER\HP LASERJET
4200") > 0 Then
.FirstPageTray = 1262
.OtherPagesTray = 1262
End If
End With
End If
End If
' Print the document
'ActiveDocument.PrintOut
' Return paper tray settings to auto select
With ActiveDocument.PageSetup
***** .FirstPageTray = wdPrinterDefaultBin *****
.OtherPagesTray = wdPrinterDefaultBin
End With
End Sub
2003. The first (LetterheadBond) inserts a continuous
section break at the top of the document's second page.
The second (PrintFinal) checks the user's ActivePrinter
and sets the print trays accordingly. After printing, it
is supposed to return the trays to the user's default
setting.
Problem is, PrintFinal generates an error message when it
tries to reset the trays. If I run that code without
running LetterheadBond first, it goes fine. But after
splitting the document into sections, PrintFinal
complains...
Run-time error '4608':
Value out of range
....when I tell it...
ActiveDocument.PageSetup.FirstPageTray =
wdPrinterDefaultBin
Why is this? Is there something I can do to get VBA to
change the entire documents' tray settings at once? My
code follows. I've added astericks where the error
occurs.
I know my code is something of an eyesore, but thanks for
any help.
******************************
Sub FormatLetterheadBond()
' Format the first page
Selection.HomeKey Unit:=wdStory
With Selection.PageSetup
.TopMargin = InchesToPoints(1.8)
.BottomMargin = InchesToPoints(1)
.LeftMargin = InchesToPoints(1.9)
.RightMargin = InchesToPoints(1)
End With
' If there is a second page...
If ActiveDocument.BuiltInDocumentProperties
(wdPropertyPages) > 1 Then
' ...Then jump to second page
Application.Browser.Next
' If the second page is not an envelope...
If Selection.PageSetup.PaperSize <>
wdPaperEnvelope10 Then
' ...Then insert a section break
Selection.InsertBreak
Type:=wdSectionBreakContinuous
' Format the remaining pages
With Selection.PageSetup
.TopMargin = InchesToPoints(1)
.BottomMargin = InchesToPoints(1)
.LeftMargin = InchesToPoints(1)
.RightMargin = InchesToPoints(1)
End With
End If
End If
End Sub
----------------------------
Sub PrintFinal()
' Get the printer
Dim Printer As String
Printer = UCase(Application.ActivePrinter)
' Set the first page to letterhead (based on printer)
Selection.HomeKey Unit:=wdStory
With Selection.PageSetup
' LaserJet 4
If InStr(Printer, "\\SBSERVER\ANNEX HP4 PLUS") >
0 Then
.FirstPageTray = wdPrinterLowerBin
.OtherPagesTray = wdPrinterUpperBin
End If
' LaserJet 4200
If InStr(Printer, "\\SBSERVER\HP LASERJET 4200")
.FirstPageTray = 12650 Then
.OtherPagesTray = 1262
End If
End With
' If there is a second page...
If ActiveDocument.BuiltInDocumentProperties
(wdPropertyPages) > 1 Then
' ...Then jump to second page
Application.Browser.Next
' If the second page is not an envelope...
If Selection.PageSetup.PaperSize <>
wdPaperEnvelope10 Then
' ...Then set the second and subsequent pages to
bond (based on printer)
With Selection.PageSetup
' LaserJet 4
If InStr(Printer, "\\SBSERVER\ANNEX HP4
PLUS") > 0 Then
.FirstPageTray = wdPrinterUpperBin
.OtherPagesTray = wdPrinterUpperBin
End If
' LaserJet 4200
If InStr(Printer, "\\SBSERVER\HP LASERJET
4200") > 0 Then
.FirstPageTray = 1262
.OtherPagesTray = 1262
End If
End With
End If
End If
' Print the document
'ActiveDocument.PrintOut
' Return paper tray settings to auto select
With ActiveDocument.PageSetup
***** .FirstPageTray = wdPrinterDefaultBin *****
.OtherPagesTray = wdPrinterDefaultBin
End With
End Sub