View Single Post
  #8   Report Post  
Posted to microsoft.public.word.tables
jpreman jpreman is offline
external usenet poster
 
Posts: 11
Default Splitting Tables

Hi Macropod,

Thank you very much for the macro. I am sure it will be of grate help to me.

Cheers

"macropod" wrote:

Hi jpreman,

The following macro vertically splits all tables in a document that exceed
the horizontal print margins, replicating the first column along the way.
Single-column and two-column tables, including any generated by the split
process, are ignored. Note the 6 lines marked with an '*'. You can delete
these if column 1 is not to be replicated.

You may have to fix the odd line that gets wrapped where it shouldn't as a
result of the posting, but that shouldn't be too difficult.

Sub TableSplit()
Application.ScreenUpdating = False
Dim oLeftMargin As Single, oRightMargin As Single, oGutter As Single
Dim oPageWidth As Single, oPrintWidth As Single, oTableWidth As Single
Dim oTable, oCounter As Integer, i As Integer, j As Integer
If ActiveDocument.Tables.Count = 0 Then Exit Sub
With ActiveDocument.PageSetup
oLeftMargin = .LeftMargin
oRightMargin = .RightMargin
oGutter = .Gutter
oPageWidth = .PageWidth
End With
oPrintWidth = oPageWidth - oLeftMargin - oRightMargin - oGutter
oCounter = 1
Restart:
For j = oCounter To ActiveDocument.Tables.Count
oTable = ActiveDocument.Tables(j)
With ActiveDocument.Tables(j)
.AllowAutoFit = False
.PreferredWidth = 0
End With
oTableWidth = 0
If oTable.Columns.Count 3 Then GoTo SkipTable
For i = 1 To oTable.Columns.Count
oTableWidth = oTableWidth + oTable.Columns(i).Width
If oTableWidth oPrintWidth Then
oTableWidth = oTableWidth - oTable.Columns(i).Width
oTable.Columns(i).Select
With Selection
.MoveRight Unit:=wdCharacter, Count:=oTable.Columns.Count - i + 1,
Extend:=wdExtend
.Copy
.Columns.Delete
.MoveDown Unit:=wdLine, Count:=oTable.Rows.Count
.InsertParagraph
.MoveDown Unit:=wdLine, Count:=1
.Paste
End With
oCounter = j
'Delete the next 6 lines (marked '*) if column 1 is not to be
replicated
oTable.Columns(1).Select '*
With Selection '*
.Copy '*
.MoveDown Unit:=wdLine, Count:=2'*
.Paste '*
End With '*
GoTo Restart
End If
Next
SkipTable:
Next
Application.ScreenUpdating = True
End Sub

Cheers

--
macropod
[MVP - Microsoft Word]


"jpreman" wrote in message
...
Hi macropod,

Thanks for your response.

Though it was not my immediate issue, I have faced what you have referred

at
many a times. I am sure the macro you have will be of much use to me.



"macropod" wrote:

Hi jpreman,

If you need to split a table because you've changed the page size and

the
table's now too wide, I have a macro I've coded to deal with that. It

isn't
coded to handle tables with cells merged across columns, and is designed

to
replicate the left-most column for each new table. If that's what you're
trying to achieve, let me know and I'll post the code.

Cheers

--
macropod
[MVP - Microsoft Word]


"jpreman" wrote in message
...
Thank you for reading this post.

I know it is possible to split a table horizontally. Is there a way a
table
could be split vertically?