Page setup

F

Fuzzhead

I run the Record Macro to record my page setup. Below is what I get. But when
I try to run it I get the following error: ‘Value out of Range’. When I
debug it’s at the following line in the macro: ‘.TopMargin =
InchesToPoints(0.75)’. What is wrong with this macro?

With ActiveDocument.Styles(wdStyleNormal).Font
If .NameFarEast = .NameAscii Then
.NameAscii = ""
End If
.NameFarEast = ""
End With
With ActiveDocument.PageSetup
.Orientation = wdOrientPortrait
.TopMargin = InchesToPoints(0.75)
.BottomMargin = InchesToPoints(0.75)
.LeftMargin = InchesToPoints(0.8)
.RightMargin = InchesToPoints(0.8)
.HeaderDistance = InchesToPoints(0.75)
.FooterDistance = InchesToPoints(0.75)
.PageWidth = InchesToPoints(8.5)
.PageHeight = InchesToPoints(11)
.FirstPageTray = wdPrinterDefaultBin
.OtherPagesTray = wdPrinterDefaultBin
.SectionStart = wdSectionNewPage
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = True
.MirrorMargins = False
.TwoPagesOnOne = False
.BookFoldPrinting = False
.BookFoldRevPrinting = False
.BookFoldPrintingSheets = 1
.GutterPos = wdGutterPosLeft
End With
 
R

Russ

Hey FuzzHead,
Just a guess on my part.
Maybe Word will happily record your current settings in the macro, but when
you run it, your current **printer setup** is also looked at during Page
Setup setup changes and if they disagree, you get the 'Value out of range'
message. You sometimes can see the results of this if you got a document
loaded with text and you go into Print Preview and parts of you header or
footer or main body of text is chopped off. Word looks at your current
'default' printer device driver code to determine what is a 'Page' size.
That's why the term 'Page' is a unreliable quantity. When you connect to
another printer the amount on a 'Page' might be different.
Is that what is happening here?
 
R

Russ

Clarification inline.
Hey FuzzHead,
Just a guess on my part.
Maybe Word will happily record your current settings in the macro, but when
you run it, your current **printer setup** is also looked at during Page
Setup setup changes and if they disagree, you get the 'Value out of range'
message. You sometimes can see the results of this if you got a document
loaded with text and you go into Print Preview and parts of your header or
footer or main body of text is chopped off. Word looks at your current
'default' printer device driver code to determine what is a 'Page' size.
I should have said "what is a 'Page' size limit."
 
F

Fuzzhead

Hi Russ,

I think thats what is happening. I can open one document and the macro runs
fine. I open the next document and I get the error. I went into print preview
 
R

Russ

FuzzHead,

Record the Page Setup in a macro while the good document is open and the bad
document is not open. For instance, temporarily change a number, but then
set it back to its original value and then close out the Page Setup dialog
and stop the recording. If you now run that new macro, there should be no
error message.
If there is no error message, then open the bad document and run the new
macro and it should change the bad document's setting so that it falls
within the boundaries of your current default printer. If everything is OK
and you are happy then resave that bad document in order to turn it into a
good document.

In order to find out what the current limits are; according to your default
printer, you can experiment by making changes in the margins and looking at
a document that is loaded with text in print preview. Back off on the
numbers when the text gets chopped off in print preview. When everything is
set to the largest page size within the margins, then record another macro
for the page settings and name it Maximum_Page_Setting to run it on other
documents as a known starting point. Then you would know that you could not
set the page larger, but you have the option to set part of the page
smaller.
This should work unless you connect to a different printer, whose limits
might be different.
Let us know if this solves your problem.
 
F

Fuzzhead

Russ,

This did not work. I still get the error message. Also I am not the only one
that is correcting the documents and we are all connected to different
printers. I think I just need to tell all the others that we will have to do
the page setup manually.

Fuzzhead
 
R

Russ

Fuzzhead,
I would probably open the page setup while a bad document is loaded and if
any values are different than what was recorded with a good document active,
try to change those to match what the good document values had. If the
'good' values work by entering them manually, then I am at a loss why a
macro works for some documents, but not for others. Are you working with
English language documents? Maybe the text is anchored and the page can't be
made smaller, once set?
 
F

Fuzzhead

Russ,

Yes these are English language documents. Also these are converted
WordPerfect documents. I feel that the problem is in the conversion to Word
that some of the documents were not converted cleanly. I can’t see anything
obvious in the bad documents that are different from the ones that work but
not sure where to really look or what to look for.
 
E

Ed

Hi Fuzzhead (& Russ),

I've seen a problem like this (in our case it was with some code that was
used in a print macro to set the paper trays to print from).

The problem only occurred with certain documents and these all had more than
one section. We can't be sure but we think the documents were created in part
by pasting stuff in from existing documents (possibly including one or more
section breaks).

We never got the problem with "ordinary" multiple section documents, only
with ones that we think had had stuff pasted in.

You might be getting a similar issue with converted documents.

As a workaround in the macro, we modified the code to avoid using the
ActiveDocument.PageSetup object and, instead, loop through the sections and
use the section-level PageSetup objects. That worked in our case.

E.g. instead of ..
-----------------------------------------------------------------------------------------------
With ActiveDocument.PageSetup
.... do page setup stuff
End Wit
-----------------------------------------------------------------------------------------------

We used something like ..
-----------------------------------------------------------------------------------------------
Dim Sec as Section
.....
.....


For Each Sec in ActiveDocument.Sections
With Sec.PageSetup
.... do page setup stuff
End With
Nex
 
R

Russ

Ed,
Thanks for the insight and solution.
I would have never thought that a rogue section pasted from a previous page
setup, that worked with another printer, would corrupt the attempt to change
the setup at the top level for the entire document, working with a different
printer.
But it makes sense that the one who pasted wanted the original formatting of
the source document, which also carried over the previous page setup.
I have never thought about doing different page setups for different
sections, either.
I love learning new things from this forum.
 
E

Ed

Hi Russ (& Fuzzhead),

You're welcome.
I love learning new things from this forum.

Me too, both generally and especially on those occasions when the computer
is about to be hurled out of the window :)

Regards.

Ed
 
R

Rich

I have found a method for fixing document thats experience this problem. If
you need to set the activedocument.pageset properties.

I have tested this on a number of documents and would appreciate any feedback.

To fix the problem the I have been saving the documents as XML and then
editing the XML directly.

Within each section you may find the following line of XML : <w:docGrid
w:line-pitch="360"/>

It usually comes right before a </w:sectPr> tag which is what I search on.
Now for some reason this setting must be the same in each section to avoid
the 4608 Value out of range error.

Note it must be the same in each section therefore if it is present in any
section then it must be present in all sections. And it also seems to work if
not present in any sections.

Once done open the document in word and re-save it as a word doc.

What I would really like to find is a way to set this properties without the
hassle of converting it to XML. Any one have any ideas what this setting
relates to ?
 
E

Ed

Hi Rich,

Nice detective work!

I don't think I can offer any advice on this (at least not at this point).

If you haven't already found them, one or more of these *might* provide some
help:

Office2003 XML Reference Schemas:

http://www.microsoft.com/downloads/...52-3547-420A-A412-00A2662442D9&displaylang=en

WordprocessingML Primer:

http://66.102.9.104/search?q=cache:...L_Download.doc+<w:DocGrid&hl=en&ct=clnk&cd=27

Integrating Office with the rest of the World:

http://66.102.9.104/search?q=cache:...apter/ch02.pdf+<w:DocGrid&hl=en&ct=clnk&cd=41

It might also be worth posting your findings in a new post as there probably
aren't many people following this thread.

Regards.

Ed
 
R

Rich

Hi Ed,

Thanks for the link to the Office2003 XML Reference Schemas I had been
looking for those. Anyway with the reference and a little more detective work
I got a much easier solution now. I started a new thread in this group the
title is 'PageSetup + Section Breaks = Value out of range Run-time Error
4608' for those that want to fix the documents through the word interface.

To cut a long story short. to fix the documents:

ActiveDocument.PageSetup.LinesPage = 38 'Default for A4
ActiveDocument.PageSetup.LinesPage = 36 'Default for Letter

So I'd gues that mixing sections from docs of different page sizes is what
causes the error to manifest itself in some documents.
 

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

Top