Method KeepWithNext has failed error message when used with Excel

A

Alex St-Pierre

Hello!
I use automation to program a word report from excel vba. When I write the
following lines, I got the error msg Method _ParagraphFormat has failed. It
works 99% of the time. I don't know why it gives this error message sometimes.
Set oRange = docWord.Paragraphs(i).Range
oRange.ParagraphFormat.KeepWithNext = True 'error
oRange.ParagraphFormat.KeepTogether = True 'error too
Sometimes, only one or both gives error.. It often happens inside a table
when it takes 2 pages. I don't know what I can do in Excel to avoid that.
oRange.ParagraphFormat.KeepTogether = 99999999 or 0 before giving an error.
Thanks a lot!
Alex
 
J

Jezebel

Word uses 99999999 as a pseudo constant to mean 'mixed' or 'undefined'. It's
the value you get if what you're looking at includes more than one value
(such as the font size for a range that includes text of different sizes).

Why not trap the error, and treat the occurrences as a special case? Apart
from that it's hard to diagnose unless you can see some pattern in the
paragraphs that throw the error.
 

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