doctorjones_md
2006-11-11 07:49:25 UTC
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
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