I'm having a problem with some VB.NET code that is using automation to create
and print a Word document. When I try to set the page margins in code, I'm
getting an error 4608, "Value out of range" error.

When I check the value of the TopMargin property before I try to set it,
it's got a value of 9999999.0. And then when I try to set the value to 43.2
points (.6 inches), which is well withing the allowable range, I get the
error.

The code looks something like:

' wvhWndWord is defined as Word.Application, WithEvents
With wvhWndWord
.Visible = True
.WindowState = Word.WdWindowState.wdWindowStateMaximize
' wvnDocNo is defined as Word.Document
wvnDocNo = .Documents.Open(wvDocName, , True, True)

With wvnDocNo.PageSetup
.TopMargin = .Application.InchesToPoints(0.6)
....

As soon as I try to set .TopMargin, I get the error. I have made sure that
the .Application.InchesToPoints(0.6) is working. This returns a value of
43.2.

Thanks for any help you can give.

Re: VB.NET to Word: Error 4608 - Value Out Of Range by Jonathan

Jonathan
Tue Jun 06 08:58:36 CDT 2006


"DaveP" <DaveP@discussions.microsoft.com> wrote in message
news:BF8D4660-3467-4720-8321-D8CA0503960C@microsoft.com...
> I'm having a problem with some VB.NET code that is using automation to
> create
> and print a Word document. When I try to set the page margins in code,
> I'm
> getting an error 4608, "Value out of range" error.
>
> When I check the value of the TopMargin property before I try to set it,
> it's got a value of 9999999.0.

That means that different sections of the document have different margins.


> And then when I try to set the value to 43.2
> points (.6 inches), which is well withing the allowable range, I get the
> error.

This may be for a number of reasons. Perhaps one of the sections is
protected.


>
> The code looks something like:
>
> ' wvhWndWord is defined as Word.Application, WithEvents
> With wvhWndWord
> .Visible = True
> .WindowState = Word.WdWindowState.wdWindowStateMaximize
> ' wvnDocNo is defined as Word.Document
> wvnDocNo = .Documents.Open(wvDocName, , True, True)
>
> With wvnDocNo.PageSetup
> .TopMargin = .Application.InchesToPoints(0.6)
> ....
>
> As soon as I try to set .TopMargin, I get the error. I have made sure
> that
> the .Application.InchesToPoints(0.6) is working. This returns a value of
> 43.2.
>
> Thanks for any help you can give.

Since the topMargin is a Section property, I suggest you iterate through the
Sections collection if wvnDocNo and set TopMargin separately for each
Section. Then, if the error recurs, let us know what is special about the
section where it happens.


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup