Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / November 2006

Tip: Looking for answers? Try searching our database.

Preventing a Table from spanning multiple pages

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
doctorjones_md - 11 Nov 2006 07:49 GMT
Is there a way that I can keep a Table (which is inserted into Document1
from another Word document) from spanning multiple pages?  For example, with
the following code, if Table(8) in Document1 is near the bottom of the page,
I need to write some code to check to see if there is room on the page to
ADD a new Row and insert the data from ExportDoc without having to carry
over onto the next page -- basically, if there isn't room on the page to
include the NEW row of data, then I need to insert a page break before
Table(8) in Document1 -- how can I do this?

Option Explicit

   Dim pTable1 As Table
   Dim pTable2 As Table
   Dim pIndex As Long
   Dim pRange As Word.Range
   Dim ExportDoc As Word.Document

Private Sub cbxDelivery_Click()

   Set ExportDoc = Documents.Open("H:\Services\Delivery.doc")
   Set pTable1 = ExportDoc.Tables(1)
   Set pTable2 = Documents("Document1").Tables(8) 'Sets Table 8 as the
insertion point

       If Me.cbxMS_IDE.Value = True Then

       pTable1.Rows.Add BeforeRow:=pTable2.Rows(3) 'Sets the insertion
point before Row 3
           For pIndex = 1 To pTable1.Columns.Count
               Set pRange = pTable1.Cell(2, pIndex).Range 'Selects Row 2 in
ExportDoc
               pRange.End = pRange.End - 1
               pRange.Copy
               pTable2.Cell(3, pIndex).Range.Paste 'Pastes data in Row 3 of
Table 8 in Document1

            Next

           Me.cmdOK.Enabled = True

       End If

   ExportDoc.Close
   Set ExportDoc = Nothing

End Sub

Much Thanks in Advance

Shane
Jezebel - 11 Nov 2006 08:03 GMT
You can use the Information() function to tell you what page a range is on:
so you could check what page the table starts on --

pTable.Cell(1,1).Range.Information(wdActiveEndPageNumber)

then add your row and check what page the first cell of the added row is on.
If different, insert your page break (or set the style for the first cell to
'page break before').

Alternatively, you might be able to solve the problem by setting all the
styles in the table to 'Keep with next'. In general, style-based solutions
are better than code-based: less work, and the document is more likely to
remain correct after subsequent editing or if displayed on a different
computer.

> Is there a way that I can keep a Table (which is inserted into Document1
> from another Word document) from spanning multiple pages?  For example,
[quoted text clipped - 46 lines]
>
> Shane
doctorjones_md - 11 Nov 2006 10:56 GMT
Jezebel,

I took your advice to set the styles in the tables to "Keep With Next" --  
this works brillantly -- thanks again!

Shane
=================
> You can use the Information() function to tell you what page a range is
> on: so you could check what page the table starts on --
[quoted text clipped - 61 lines]
>>
>> Shane
Lüko Willms - 12 Nov 2006 07:56 GMT
Am Sat, 11 Nov 2006 10:56:44 UTC,  schrieb "doctorjones_md"
<doctorjones_md(Remove This)@yahoo.com>  auf
microsoft.public.word.vba.general :

> I took your advice to set the styles in the tables to "Keep With Next" --  
> this works brillantly -- thanks again!

 I'm not sure if this is what I have in mind -- my MS-Word 'speaks'
German and uses different designations -- but you can

 a) activate the option that a page break within a row is not
permitted;
 e.g. like this:  myTable.AllowPageBreaks = False

and
 b) designate the first Row(s) as table headers which are to be
repeated on every page.
 e.g. like this: myTable.Rows(1).HeadingFormat = True

Yours,
L.W.
Doctorjones_md - 15 Nov 2006 15:28 GMT
Luko,

Thanks for your suggestion -- a variation of what Jezebel suggested as
well -- this solved my problem.

Thanks again.

> Am Sat, 11 Nov 2006 10:56:44 UTC,  schrieb "doctorjones_md"
> <doctorjones_md(Remove This)@yahoo.com>  auf
[quoted text clipped - 17 lines]
> Yours,
> L.W.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.