L
LDMueller
I have a macro which I created by recording the actual steps. This macro
basically takes a 3 page letter, for example and formats the first page to
print from our letterhead tray (tray 1) and all other pages to print from
bond paper tray (tray 3). Our printer is an HP Laserjet 4250.
My problem is this. Sometime's my letter has different margins, etc. (I'm
assuming this is the problem) and because of this I get a Run-time error
'4608: Value out of range error. When I try to Debug it, it will continually
error out on any of the lines under "With ActiveDocument.PageSetup".
I would sincerely appreciate some assistance since I really need to automate
the page setups for documents.
Sub letter1()
'
' letter1 Macro
' Format document to print on Letterhad Paper with Bond for all following
pages
' Macro created 9/27/05 by Leigh Descher Mueller for CWA
'
' Go to top of page
Selection.HomeKey Unit:=wdStory
' Select all
Selection.WholeStory
' Page setup, apply to Whole document,
' First page = Tray 3, Other pages = Tray 3
With ActiveDocument.Styles(wdStyleNormal).Font
If .NameFarEast = .NameAscii Then
.NameAscii = ""
End If
.NameFarEast = ""
End With
With ActiveDocument.PageSetup
.LineNumbering.Active = False
.Orientation = wdOrientPortrait
.TopMargin = InchesToPoints(1)
.BottomMargin = InchesToPoints(1)
.LeftMargin = InchesToPoints(1)
.RightMargin = InchesToPoints(1)
.Gutter = InchesToPoints(0)
.HeaderDistance = InchesToPoints(1)
.FooterDistance = InchesToPoints(1)
.PageWidth = InchesToPoints(8.5)
.PageHeight = InchesToPoints(11)
.FirstPageTray = 260
.OtherPagesTray = 260
.SectionStart = wdSectionNewPage
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = True
.VerticalAlignment = wdAlignVerticalTop
.SuppressEndnotes = True
.MirrorMargins = False
.TwoPagesOnOne = False
.BookFoldPrinting = False
.BookFoldRevPrinting = False
.BookFoldPrintingSheets = 1
.GutterPos = wdGutterPosLeft
End With
'Go Home
Selection.HomeKey Unit:=wdStory
' F8, go to Page 2
Selection.Extend
Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:="2"
Selection.Find.ClearFormatting
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
' Page setup, Apply to Selected sections,
' First page = Tray 1, Other pages = Tray 3
With Selection.PageSetup
.LineNumbering.Active = False
.Orientation = wdOrientPortrait
.TopMargin = InchesToPoints(1)
.BottomMargin = InchesToPoints(1)
.LeftMargin = InchesToPoints(1)
.RightMargin = InchesToPoints(1)
.Gutter = InchesToPoints(0)
.HeaderDistance = InchesToPoints(1)
.FooterDistance = InchesToPoints(1)
.PageWidth = InchesToPoints(8.5)
.PageHeight = InchesToPoints(11)
.FirstPageTray = 262
.OtherPagesTray = 260
.SectionStart = wdSectionNewPage
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = True
.VerticalAlignment = wdAlignVerticalTop
.SuppressEndnotes = True
.MirrorMargins = False
.TwoPagesOnOne = False
.BookFoldPrinting = False
.BookFoldRevPrinting = False
.BookFoldPrintingSheets = 1
.GutterPos = wdGutterPosLeft
End With
'Go Home
Selection.HomeKey Unit:=wdStory
End Sub
basically takes a 3 page letter, for example and formats the first page to
print from our letterhead tray (tray 1) and all other pages to print from
bond paper tray (tray 3). Our printer is an HP Laserjet 4250.
My problem is this. Sometime's my letter has different margins, etc. (I'm
assuming this is the problem) and because of this I get a Run-time error
'4608: Value out of range error. When I try to Debug it, it will continually
error out on any of the lines under "With ActiveDocument.PageSetup".
I would sincerely appreciate some assistance since I really need to automate
the page setups for documents.
Sub letter1()
'
' letter1 Macro
' Format document to print on Letterhad Paper with Bond for all following
pages
' Macro created 9/27/05 by Leigh Descher Mueller for CWA
'
' Go to top of page
Selection.HomeKey Unit:=wdStory
' Select all
Selection.WholeStory
' Page setup, apply to Whole document,
' First page = Tray 3, Other pages = Tray 3
With ActiveDocument.Styles(wdStyleNormal).Font
If .NameFarEast = .NameAscii Then
.NameAscii = ""
End If
.NameFarEast = ""
End With
With ActiveDocument.PageSetup
.LineNumbering.Active = False
.Orientation = wdOrientPortrait
.TopMargin = InchesToPoints(1)
.BottomMargin = InchesToPoints(1)
.LeftMargin = InchesToPoints(1)
.RightMargin = InchesToPoints(1)
.Gutter = InchesToPoints(0)
.HeaderDistance = InchesToPoints(1)
.FooterDistance = InchesToPoints(1)
.PageWidth = InchesToPoints(8.5)
.PageHeight = InchesToPoints(11)
.FirstPageTray = 260
.OtherPagesTray = 260
.SectionStart = wdSectionNewPage
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = True
.VerticalAlignment = wdAlignVerticalTop
.SuppressEndnotes = True
.MirrorMargins = False
.TwoPagesOnOne = False
.BookFoldPrinting = False
.BookFoldRevPrinting = False
.BookFoldPrintingSheets = 1
.GutterPos = wdGutterPosLeft
End With
'Go Home
Selection.HomeKey Unit:=wdStory
' F8, go to Page 2
Selection.Extend
Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:="2"
Selection.Find.ClearFormatting
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
' Page setup, Apply to Selected sections,
' First page = Tray 1, Other pages = Tray 3
With Selection.PageSetup
.LineNumbering.Active = False
.Orientation = wdOrientPortrait
.TopMargin = InchesToPoints(1)
.BottomMargin = InchesToPoints(1)
.LeftMargin = InchesToPoints(1)
.RightMargin = InchesToPoints(1)
.Gutter = InchesToPoints(0)
.HeaderDistance = InchesToPoints(1)
.FooterDistance = InchesToPoints(1)
.PageWidth = InchesToPoints(8.5)
.PageHeight = InchesToPoints(11)
.FirstPageTray = 262
.OtherPagesTray = 260
.SectionStart = wdSectionNewPage
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = True
.VerticalAlignment = wdAlignVerticalTop
.SuppressEndnotes = True
.MirrorMargins = False
.TwoPagesOnOne = False
.BookFoldPrinting = False
.BookFoldRevPrinting = False
.BookFoldPrintingSheets = 1
.GutterPos = wdGutterPosLeft
End With
'Go Home
Selection.HomeKey Unit:=wdStory
End Sub