PageSetup + Section Breaks = Value out of range Run-time Error 4608

R

Rich

Hi All,

I have seen this problem on a few forums and have found a solution that has
so far worked 100%. If you don't want all the details skip to the second to
last line.

The problem occurs when using a VBA macro to set certain Page Setup
Properties such as

ActiveDocument.PageSetup.FirstPageTray=1
ActiveDocument.PageSetup.RightMargin=10

On trying this on some documents that contain section breaks an error is
received
Run-time error '4608': Value Out Of Range

The only solutions I could find were to replace all section breaks with page
breaks which in a lot of circumsatnces works fine. But if the section breaks
are necessary then there are ways to correct the document.

After hours of frustration I decided I needed to compare a working document
with a broken document and the only way I could think to do this was to save
it as XML and view it in a text editor. What I found was that there is an
attribute in each section which has the XML of <w:docGrid
w:line-pitch="360"/> or similar this XML can usually be found just before
</w:sectPr>.

Now in a healthy document this setting is the same in each section
throughout the document. And in a document that causes the error the
line-pitch is different in one or more of the sections.
--Note if the setting is present in any one section then it must be the same
value and included in all sections.


There is also a simpler way I have found to correct the documents but I
don't know if the method will have any side effects. You would think that if
the 'line-pitch' was visible in the XML then there would be some where in
Word that you could set this value. However in a normal English word setup
it is impossible to find.

Usually in Word on the Page Setup dialog there are 3 tabs Margins, Paper,
Layout.

But if you go into Start->Programs->Microsoft Office->Microsoft Office
Tools->Microsoft Office 2003 Language Settings and add Korean, Chinese, or
Japanese to the enabled languages you will get an
extra tab called Document Grid and in here you can specify Grid setting.

The normal value for line-pitch seems to be 360 in the XML for (A4 Paper).
To achieve this through the word interface I have been selecting the radio
button 'Specify Line Grid Only' and then setting the Pitch in the lines
setting to 18 (set it to 17 then click the up arrow) make sure to apply to
the whole document and run the VB code again this time no error.

I was just about to ask for some help to achieve this in a macro when it
struck me I can record a macro.

ActiveDocument.PageSetup.LinesPage = 38 'achieves the same as all
the above but is a little bit easier.

Just thought I should share that knowledged with you.

Rich.
 
P

periodic

Nice. I had just this problem once. Had to remove the section break to make
it work.
 
R

Russ

Addendum below:
Hi All,

I have seen this problem on a few forums and have found a solution that has
so far worked 100%. If you don't want all the details skip to the second to
last line.

The problem occurs when using a VBA macro to set certain Page Setup
Properties such as

ActiveDocument.PageSetup.FirstPageTray=1
ActiveDocument.PageSetup.RightMargin=10

On trying this on some documents that contain section breaks an error is
received
Run-time error '4608': Value Out Of Range

The only solutions I could find were to replace all section breaks with page
breaks which in a lot of circumsatnces works fine. But if the section breaks
are necessary then there are ways to correct the document.

After hours of frustration I decided I needed to compare a working document
with a broken document and the only way I could think to do this was to save
it as XML and view it in a text editor. What I found was that there is an
attribute in each section which has the XML of <w:docGrid
w:line-pitch="360"/> or similar this XML can usually be found just before
</w:sectPr>.

Now in a healthy document this setting is the same in each section
throughout the document. And in a document that causes the error the
line-pitch is different in one or more of the sections.
--Note if the setting is present in any one section then it must be the same
value and included in all sections.


There is also a simpler way I have found to correct the documents but I
don't know if the method will have any side effects. You would think that if
the 'line-pitch' was visible in the XML then there would be some where in
Word that you could set this value. However in a normal English word setup
it is impossible to find.

Usually in Word on the Page Setup dialog there are 3 tabs Margins, Paper,
Layout.

But if you go into Start->Programs->Microsoft Office->Microsoft Office
Tools->Microsoft Office 2003 Language Settings and add Korean, Chinese, or
Japanese to the enabled languages you will get an
extra tab called Document Grid and in here you can specify Grid setting.

The normal value for line-pitch seems to be 360 in the XML for (A4 Paper).
To achieve this through the word interface I have been selecting the radio
button 'Specify Line Grid Only' and then setting the Pitch in the lines
setting to 18 (set it to 17 then click the up arrow) make sure to apply to
the whole document and run the VB code again this time no error.

I was just about to ask for some help to achieve this in a macro when it
struck me I can record a macro.

ActiveDocument.PageSetup.LinesPage = 38 'achieves the same as all
the above but is a little bit easier.

Just thought I should share that knowledged with you.

Rich.

Rich,
I felt compelled to add this quote of yours from the other thread, since it
succinctly explains the problem and solution. I agree with Ed about the nice
detective work using xml.
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 guess 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