Run-time error '4608: Value out of range error

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
 
C

Casey Mac

I have the exact same error on my code: I hope some one can help. im using
word 2003

ActiveDocument.PageSetup.DifferentFirstPageHeaderFooter = True
Set oRng = ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary).Range
oRng.ParagraphFormat.Alignment = wdAlignParagraphCenter
NormalTemplate.AutoTextEntries("Page X of Y").Insert Where:=oRng,
RichText:=True
 
J

Jean-Guy Marcil

Casey Mac was telling us:
Casey Mac nous racontait que :
I have the exact same error on my code: I hope some one can help. im
using word 2003

ActiveDocument.PageSetup.DifferentFirstPageHeaderFooter = True
Set oRng =
ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary).Range
oRng.ParagraphFormat.Alignment = wdAlignParagraphCenter
NormalTemplate.AutoTextEntries("Page X of Y").Insert Where:=oRng,
RichText:=True

Your code ran fine as is (Word 2003) on my machine.
By the way, you may be experiencing the same error message as the OP, but it
is definitely a different problem. It would be better to start a new
thread...

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
J

Jean-Guy Marcil

LDMueller was telling us:
LDMueller nous racontait que :
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.

First, I would suggest that you clean up your macro...
See
http://word.mvps.org/faqs/macrosvba/ModifyRecordedMacro.htm


--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
L

LDMueller

Thank your for your response. This information was very helpful, however, I
had cleaned it up initally and when it didn't work, I put everything back in.

The following is my updated code, however it still doesn't work. We have
Word 2003 and our printer is an HP Laserjet 4250.

Selection.WholeStory
With ActiveDocument.PageSetup
.FirstPageTray = 262
.OtherPagesTray = 260
End With

Thanks!
 
J

Jean-Guy Marcil

LDMueller was telling us:
LDMueller nous racontait que :
Thank your for your response. This information was very helpful,
however, I had cleaned it up initally and when it didn't work, I put
everything back in.

The following is my updated code, however it still doesn't work. We
have Word 2003 and our printer is an HP Laserjet 4250.

Selection.WholeStory
With ActiveDocument.PageSetup
.FirstPageTray = 262
.OtherPagesTray = 260
End With
How did you get those tray constants? (262, 260)
Those are printer specific, not Word specific.

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
L

LDMueller

Those are the constants that came up after recording the macro setting the
paper sized for that particular printer.
 
L

LDMueller

Yes, I saw that article awhile back. I tried using it and it did have a
window showing paper sizes, but I didn't really know what to do with the
information. This still didn't help me write a macro that worked.

Thanks anyway.
 
J

Jean-Guy Marcil

LDMueller was telling us:
LDMueller nous racontait que :
Yes, I saw that article awhile back. I tried using it and it did
have a window showing paper sizes, but I didn't really know what to
do with the information. This still didn't help me write a macro
that worked.

Thanks anyway.


Did you look at the other three pages as well:

Controlling the Printer from Word VBA
Part 2: Using VBA to control Duplex, Color Mode and Print Quality
http://pubs.logicalexpressions.com/Pub0009/LPMArticle.asp?ID=116

Controlling the Printer from Word VBA
Part 3: Dealing with Different Paper Sizes
http://pubs.logicalexpressions.com/Pub0009/LPMArticle.asp?ID=132

Controlling the Printer from Word VBA
Part 4: Getting printer driver details
http://pubs.logicalexpressions.com/Pub0009/LPMArticle.asp?ID=183

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

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

Similar Threads

Macro to fix header 0
Letterhead Macro 1
Page setup 14
Problem with Office 2003 vba in Office 2007 6
macro problems 0
Word macro help- formatting and printing 2
Using Excel VBA to Format Word Document 0
Script 2

Top