Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word Automation - Keeping Paragraphs Together

Status
Not open for further replies.

csr

Programmer
Jul 20, 2000
507
I am trying to keep a group of paragraphs together when the Word document is paginated. The KeepTogether property seems to be the ticket. My plan is to define a range when I am at the beginning of my group of paragraphs, save the START property of that range, Then insert my various paragraphs while collapsing ranges periodically, then finally save the END property of the last range I am using.

Then I will redefine the range using the START and END values I have saved and utilize the oRange.Paragraphs.KeepTogether property to keep those various paragraphs together.

Unfortunately, it does not seem to work. Any insight into why that might be. I have include a skeleton of some of my code below ...

A range object has been established ...
nRangeStart = oRange.start

<Some Inserts and range collapses for a few paragraphs>


oRange = oDoc.Range()
nRangeEnd = oRange.end
oRange.Start = nRangeStart && From the initial Range
oRange.Paragraphs.KeepTogether = .t.
oRange.Collapse(wdCollapseEnd)


Don


 
Well, never mind ...

I discovered that the property KeepWithNext is the one I should have been using.

Onward and Upward ...



Don


 
I am still struggling with this concept.

If I string consecutive paragraphs together with KeepNextTogether, they all get hooked together and the breaks continue to occur within paragraphs defeating my purpose.

I tried to separate each paragraph with a blank paragraph (just a carriage return) with the property KeepNextTogether set to FALSE and that didn't seem to have any effect either.

Does anyone have any insight into this ?



Don


 
Don,

First of all, you shouldn't need to set KeepNextTogether for the last paragraph of the set. In other words, if you want to keep Para A, Para B and Para C together, you would set the property for A and B, not C.

Interspersing the paras with carriage-returns, and setting the property to False for the carriage-returns .... all that will give you is a guaranteed blank line after each para, but no guanarantee that the actual non-blank paras will be kept together.

Also, keep in mind that, if the total length of the kept-toghether paras exceeds one page, they will break across the page boundary (obviously); there is nothing you can do about that.

The only other thing I can suggest is that you try reproducing the behaviour you want within Word itself, by manually setting the properties in the Format Paragraph dialogue. At least, that way you will know whether it is your VFP code or your understanding of Word which is at fault.

Mike



Mike Lewis
Edinburgh, Scotland

My Visual Foxpro web site: My Crystal Reports web site:
 
Mike:

This statement you made ...

>>Also, keep in mind that, if the total length of the kept->>toghether paras exceeds one page, they will break across >>the page boundary (obviously); there is nothing you can >>do about that.

is what I am trying to prevent by putting a blank line with a NOT KEEPTOGETHER assignment between each paragraph. Otherwise, that is exactly what happens.

I do not understand why that would not work ?




Don


 
Well, that is encouraging that it makes sense to you also. However, as of right now, it does not seem to be working. I will need to do some more work on it to be sure.

Thanks for the input.


Don


 
This is a difficult concept, but I think I've gotten a handle on it (I don't know why it always starts out so difficult):

There are two different properties for paragraphs: "Keep with Next" and "Keep Together".

"Keep With Next" only ensures that the last line of one paragraph will be juxtaposed with the first line of the following paragraph.

"Keep Together" guarantees that a page break won't happen in the middle of the paragrah that is marked as such.

If you have several paragraphs that are several lines each, and you need them to stay together on one page, you must mark them as BOTH "Keep with Next" AND "Keep Together"
 
WGCS:

That is interesting. I will try that. Thanks.



Don


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top