dbasnett
dbasnett

Reputation: 11773

Word macro error - Runtime Error 4608, Value out of range

We have a macro we run to format the page for our publisher. There are several documents that use this macro. For smaller documents the macro runs without error, for larger documents we receive the error in the subject line of this thread.

Small document - <= 256KB

Large document - >= 500KB

For the documents that have the error I can open them in Word and manually make the settings without a problem.

Here is the second version of the macro

Function pagestuffB() As String
'
' Format for Publisher
'
'
Dim rv As String
rv = ""
On Error GoTo ErrorHndlr:
    With Application
        .Options.Pagination = False
        .ScreenUpdating = False
        With .ActiveDocument.PageSetup
            .PaperSize = wdPaperLetter
'            .PageWidth = InchesToPoints(8.5)
'            .PageHeight = InchesToPoints(11)
            .Orientation = wdOrientPortrait
            .MirrorMargins = True 'ERROR HERE
            .TopMargin = InchesToPoints(1.34)
            .HeaderDistance = InchesToPoints(0.98)
            .BottomMargin = InchesToPoints(1)
            .FooterDistance = InchesToPoints(0.8)
            .LeftMargin = InchesToPoints(1.61)
            .RightMargin = InchesToPoints(1.4)
            .Gutter = InchesToPoints(0)
            .SectionStart = wdSectionContinuous
            .OddAndEvenPagesHeaderFooter = True
            .DifferentFirstPageHeaderFooter = True
            .LineNumbering.Active = False

            .FirstPageTray = wdPrinterDefaultBin
            .OtherPagesTray = wdPrinterDefaultBin
            .VerticalAlignment = wdAlignVerticalTop
            .SuppressEndnotes = False
            .TwoPagesOnOne = False
            .BookFoldPrinting = False
            .BookFoldRevPrinting = False
            .BookFoldPrintingSheets = 1
            .GutterPos = wdGutterPosLeft
        End With
    End With
    pagestuffB = rv
Exit Function

ErrorHndlr:
    If rv = "" Then
        rv = "Macro error " & Err.Number
        Select Case Err.Number
            Case Else
        End Select
    End If

    Resume Next
End Function

Version info: Word 2010, VS 2012.

I have the document that failed and will provide it if needed.

EDIT: The documents are here

This is the latest version of the macro, which actually runs, but.... It took .5 hours to format the two documents, two of the smallest, in the link above.

Function pagestuffB() As String
'
' Format for Publisher
'
'
Dim rv As String
rv = ""
On Error GoTo ErrorHndlr:
    With Application
        .Options.Pagination = False
        .ScreenUpdating = False
        .WindowState = wdWindowStateMinimize
    End With
    Dim oSec As Section
    For Each oSec In Selection.Sections
        With oSec.PageSetup
            .Orientation = wdOrientPortrait 'moved per macropod
            .PaperSize = wdPaperLetter
            .MirrorMargins = True
            .TopMargin = InchesToPoints(1.34)
            .HeaderDistance = InchesToPoints(0.98)
            .BottomMargin = InchesToPoints(1)
            .FooterDistance = InchesToPoints(0.8)
            .LeftMargin = InchesToPoints(1.61)
            .RightMargin = InchesToPoints(1.4)
            .Gutter = InchesToPoints(0)
            .SectionStart = wdSectionContinuous
            .OddAndEvenPagesHeaderFooter = True
            .DifferentFirstPageHeaderFooter = True

            .LineNumbering.Active = False
            .FirstPageTray = wdPrinterDefaultBin
            .OtherPagesTray = wdPrinterDefaultBin
            .VerticalAlignment = wdAlignVerticalTop
            .SuppressEndnotes = False
            .TwoPagesOnOne = False
            .BookFoldPrinting = False
            .BookFoldRevPrinting = False
            .BookFoldPrintingSheets = 1
            .GutterPos = wdGutterPosLeft
        End With
    Next oSec

    pagestuffB = rv
Exit Function

ErrorHndlr:
    If rv = "" Then
        rv = "Macro error " & Err.Number
        Select Case Err.Number
            Case Else
        End Select
    End If

    Resume Next
End Function

Upvotes: 0

Views: 3801

Answers (1)

Floam
Floam

Reputation: 704

So I removed these three lines of code and the macro worked very quickly on my computer for those two documents. It seems like you used a recorded macro to build this code. It's certainly hard to grasp what exactly you want this code to do since there are no comments describing what your code does :). Comment underneath if this suggestion does not fix your problem.

.BookFoldPrinting = False
.BookFoldRevPrinting = False
.BookFoldPrintingSheets = 1

Upvotes: 1

Related Questions