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

D

DaveP

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.
 
J

Jonathan West

DaveP said:
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.
 

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