PDA

View Full Version : Solved: Move table in MS Word down automatically



jona
01-04-2009, 07:30 PM
Hi,

I am stuck with this problem for a period of time and could not find any hints on how to solve this.

My project now is to generate a word document (with plenty of tables) from MS Excel. No major problem with that. (I am making use of paragraphs, not bookmark)

However, when tables are created, sometimes a header appears close to the end of a page with no asociated data (or one row of data) below it. In this case, I wish to start it on a fresh page instead.

Is there anyway to do that?

For example:

11340

Many thanks in advance!!!!!

Dave
01-05-2009, 12:24 AM
Please disregard. My post was in error. On re-read you are talking about Table headers not Word headers. Have a nice day! Dave

macropod
01-05-2009, 02:58 AM
Hi jona,

Simple: format the para for any one or more of the Heading Row cells as 'Keep With Next'. If any of the header cells has more than one row of text - use the one with the most rows and format its paragraph(s) as 'Keep With Next' and 'Keep Lines Together'.

jona
01-05-2009, 06:54 AM
Hi jona,

Simple: format the para for any one or more of the Heading Row cells as 'Keep With Next'. If any of the header cells has more than one row of text - use the one with the most rows and format its paragraph(s) as 'Keep With Next' and 'Keep Lines Together'.

Thanks Macropod,

I will try it out tomorrow, shall revert if have any difficulties =)

EricFletcher
01-06-2009, 08:51 AM
In addition, in the Table Properties, Row dialog, you may want to turn off the "Allow row to break across pages" checkbox. This will prevent a row with >1 line from breaking across a page as well. Keep Lines Together works much the same way, but be aware that the last row should NOT have the Keep With Next set on.

fumei
01-06-2009, 09:59 AM
Pay special attention to Eric's last sentence! I can not count the number of times people have sent me documents with "weird" breaks in documents because of this.

EricFletcher
01-06-2009, 11:13 AM
Ditto Gerry! Here are a couple of tips to help with that...

1) The Tools Options, View dialog's Formatting marks section manages what marks are visible when you click the ? button. Be sure that All is selected, then get in the habit of checking the document in the Normal view with Show All turned on. Invisible paragraph formatting attributes like Keep Together and Keep With Next are indicated by a small black square left of the margin. (They show in the Page view too, but I find I can catch more without the page breaks and header/footers getting in the way.)

2) With Word 2003, the "Reveal formatting" panel of the Task Pane (Ctrl-F1) displays all of the attributes in effect in the selection (or where the cursor is located). If you are using a wide-screen LCD monitor, there should be plenty of room to keep the Task Pane up as you work.

If you have "Show: Available formatting" set on in the Styles and Formatting panel, you can go one further: all formatting variants are shown, and you can select all instances at once by using the pull-down on the right side of the formatting description. This makes all instances visible for your review or to be changed en masse.

The 2nd tip is also useful for catching other invisible formatting attributes such as different languages or minor adjustments in font character spacing.

The Keep attributes are so useful, I have "KN" and a "KT" custom buttons on my formatting toolbar to make it easy to toggle them on and off without having to go to the Format Paragraph dialog.

fumei
01-06-2009, 01:44 PM
"The Keep attributes are so useful, I have "KN" and a "KT" custom buttons on my formatting toolbar to make it easy to toggle them on and off without having to go to the Format Paragraph dialog."

Manual formatting????


Ahem.....would not using Styles be better?

For example, I have (and this does not have to do with tables, but is the same really):

mBullet1 - style for all items in a bulleted list
mBullet1_End - style for the LAST item

Why? Because the bulleted list itself has fairly tight spacing between items, but I want the LAST one to have more space after.

I do the same thing with tables, but I do the last row format via code.

For Each Table In DocTables
Table.LastRow.Style = ummmmm, LastRowStyle

with of course LastRowStyle having Keep with Next off.

Just razing ya Eric.

jona
01-07-2009, 07:21 PM
In addition, in the Table Properties, Row dialog, you may want to turn off the "Allow row to break across pages" checkbox. This will prevent a row with >1 line from breaking across a page as well. Keep Lines Together works much the same way, but be aware that the last row should NOT have the Keep With Next set on.

For r1 = 1 To rLast
With .Rows(r1).Range.ParagraphFormat
.KeepTogether = True
.KeepWithNext = True
.SpaceBefore = 1
.LeftIndent = wdapp.InchesToPoints(0.03)
.RightIndent = wdapp.InchesToPoints(0.02)
End With
Next

Using this, it managed to push the document down to the next page. However, what I wanted was to push down tables that have less than 3 lines remaining of the page above. But the codes move tables down that contain 5 rows.

Other than that, I would like the table title to following accordingly if the table have been moved to the next page.

Are there any hint on how can I solve this?

I will be grateful for any hints or example codes posted.

macropod
01-10-2009, 12:27 AM
Hi jona,

You could use:

For r1 = 1 To rLast
With .Rows(r1).Range.ParagraphFormat
If r1 < 3 Then
.KeepTogether = True
.KeepWithNext = True
End If
.SpaceBefore = 1
.LeftIndent = wdapp.InchesToPoints(0.03)
.RightIndent = wdapp.InchesToPoints(0.02)
End With
Next

jona
01-12-2009, 08:48 PM
It works!

Thanks so much!