Keeping tables within a page 
Author Message
 Keeping tables within a page

Hi all,

I am using Word 97 and an absolute Word VBA beginner.

The very first task I wish to do is to keep all tables in a document
from being broken by page breaks. Sadly so far I can not find a style
which allows me to do this. But I think I could do the job in VBA. The
psuedocode is as follows:

FOR EACH Table IN a Document
FOR EACH Cell IN a table
FOR EACH Paragraph IN a Cell
Mark them as "Keep with Next"
NEXT
NEXT
NEXT

Could you kindly advise how I can implement the pseudocode into VBA
code? Thanks a lot.

Frankie Chow
Hong Kong.



Sun, 06 Jun 2004 18:10:03 GMT  
 Keeping tables within a page
Frankie,

Try this:

Dim t As Table, r As Row, p As Paragraph
For Each t In ActiveDocument.Tables
     For Each r In t.Rows
          If r.Index < t.Rows.Count Then
               For Each p In r.Range.Paragraphs
                    p.Range.ParagraphFormat.KeepWithNext = True
               Next p
          Else
               r.AllowBreakAcrossPages = False
          End If
     Next r
Next t

Note: This code is Word97-specific.  I'm not 100% certain but I believe
the Keep With Next feature works slightly differently in Word 2000-2002.
Note that you don't want Keep With Next on the last row, but you do want
to change its AllowBreakAcrossPages property.


-- See the MVP FAQ at http://www.mvps.org/word --------------------------
----------------- "Life is nothing if you're not obsessed." --John Waters
-------------------------------------------------------------------------
Please reply only to the newsgroup.  Note: MVPs do not work for Microsoft.

Quote:

> Hi all,

> I am using Word 97 and an absolute Word VBA beginner.

> The very first task I wish to do is to keep all tables in a document
> from being broken by page breaks. Sadly so far I can not find a style
> which allows me to do this. But I think I could do the job in VBA. The
> psuedocode is as follows:

> FOR EACH Table IN a Document
> FOR EACH Cell IN a table
> FOR EACH Paragraph IN a Cell
> Mark them as "Keep with Next"
> NEXT
> NEXT
> NEXT

> Could you kindly advise how I can implement the pseudocode into VBA
> code? Thanks a lot.

> Frankie Chow
> Hong Kong.



Sun, 06 Jun 2004 19:18:14 GMT  
 Keeping tables within a page
Hi Mark,

I have tried to run the macro, but encountered a run-time error:

Error 5991: Cannot access individual rows in this collection because the table
has vertically merged cells.

How can I get around of this restriction, i.e I want all tables to be kept
within the same page regardless of whether they contain vertically merged
cells? Please advise.

Last and very importantly I really appreciate your assistance.

Frankie Chow
Hong Kong.

Quote:

> Frankie,

> Try this:

> Dim t As Table, r As Row, p As Paragraph
> For Each t In ActiveDocument.Tables
>      For Each r In t.Rows
>           If r.Index < t.Rows.Count Then
>                For Each p In r.Range.Paragraphs
>                     p.Range.ParagraphFormat.KeepWithNext = True
>                Next p
>           Else
>                r.AllowBreakAcrossPages = False
>           End If
>      Next r
> Next t

> Note: This code is Word97-specific.  I'm not 100% certain but I believe
> the Keep With Next feature works slightly differently in Word 2000-2002.
> Note that you don't want Keep With Next on the last row, but you do want
> to change its AllowBreakAcrossPages property.


> -- See the MVP FAQ at http://www.mvps.org/word --------------------------
> ----------------- "Life is nothing if you're not obsessed." --John Waters
> -------------------------------------------------------------------------
> Please reply only to the newsgroup.  Note: MVPs do not work for Microsoft.


> > Hi all,

> > I am using Word 97 and an absolute Word VBA beginner.

> > The very first task I wish to do is to keep all tables in a document
> > from being broken by page breaks. Sadly so far I can not find a style
> > which allows me to do this. But I think I could do the job in VBA. The
> > psuedocode is as follows:

> > FOR EACH Table IN a Document
> > FOR EACH Cell IN a table
> > FOR EACH Paragraph IN a Cell
> > Mark them as "Keep with Next"
> > NEXT
> > NEXT
> > NEXT

> > Could you kindly advise how I can implement the pseudocode into VBA
> > code? Thanks a lot.

> > Frankie Chow
> > Hong Kong.



Mon, 07 Jun 2004 21:03:08 GMT  
 Keeping tables within a page
OK, that makes it much harder -- perhaps impossible -- to do using the
Row object.

What I would try is this: Place an empty paragraph under each table,
formatted to a very small font (say 1 point) so it won't be noticed.
Then run this:

  Dim t As Table
  For Each t In ActiveDocument.Tables
       t.Range.ParagraphFormat.KeepWithNext = True
  Next t


-- See the MVP FAQ at http://www.mvps.org/word --------------------------
----------------- "Life is nothing if you're not obsessed." --John Waters
-------------------------------------------------------------------------
Please reply only to the newsgroup.  Note: MVPs do not work for Microsoft.

Quote:

> Hi Mark,

> I have tried to run the macro, but encountered a run-time error:

> Error 5991: Cannot access individual rows in this collection because the table
> has vertically merged cells.

> How can I get around of this restriction, i.e I want all tables to be kept
> within the same page regardless of whether they contain vertically merged
> cells? Please advise.

> Last and very importantly I really appreciate your assistance.

> Frankie Chow
> Hong Kong.


> > Frankie,

> > Try this:

> > Dim t As Table, r As Row, p As Paragraph
> > For Each t In ActiveDocument.Tables
> >      For Each r In t.Rows
> >           If r.Index < t.Rows.Count Then
> >                For Each p In r.Range.Paragraphs
> >                     p.Range.ParagraphFormat.KeepWithNext = True
> >                Next p
> >           Else
> >                r.AllowBreakAcrossPages = False
> >           End If
> >      Next r
> > Next t

> > Note: This code is Word97-specific.  I'm not 100% certain but I believe
> > the Keep With Next feature works slightly differently in Word 2000-2002.
> > Note that you don't want Keep With Next on the last row, but you do want
> > to change its AllowBreakAcrossPages property.


> > -- See the MVP FAQ at http://www.mvps.org/word --------------------------
> > ----------------- "Life is nothing if you're not obsessed." --John Waters
> > -------------------------------------------------------------------------
> > Please reply only to the newsgroup.  Note: MVPs do not work for Microsoft.


> > > Hi all,

> > > I am using Word 97 and an absolute Word VBA beginner.

> > > The very first task I wish to do is to keep all tables in a document
> > > from being broken by page breaks. Sadly so far I can not find a style
> > > which allows me to do this. But I think I could do the job in VBA. The
> > > psuedocode is as follows:

> > > FOR EACH Table IN a Document
> > > FOR EACH Cell IN a table
> > > FOR EACH Paragraph IN a Cell
> > > Mark them as "Keep with Next"
> > > NEXT
> > > NEXT
> > > NEXT

> > > Could you kindly advise how I can implement the pseudocode into VBA
> > > code? Thanks a lot.

> > > Frankie Chow
> > > Hong Kong.



Tue, 08 Jun 2004 09:15:56 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Keeping tables on one Page

2. Keeping tables on one page

3. Can't keep table on one page

4. Identify object within subform on page within form

5. HELP: Need help in creating a table from a table within Access

6. Tables within tables?

7. keeping borders within margins

8. How: Keep Form Within The Screen Area

9. Keeping image size within acceptable range

10. Keeping a popup menu within a form

11. Scroll bar keeps scrolling within Flexgrid

12. Keep focus (within app) on modaless form

 

 
Powered by phpBB® Forum Software