View Single Post
  #14  
Old October 27th, 2006, 12:17 PM posted to microsoft.public.word.tables
macropod
external usenet poster
 
Posts: 1,231
Default The tables are turned! Well... not yet.

Still needs more work - bombs on tables with merged cells.

Cheers

--
macropod
[MVP - Microsoft Word]


"Tesla" wrote in message
...
Everyone thank macropod for alpha testing the macro, here is version 2,

much
improved:

Option Explicit
Sub TransposeTableSelected()
Dim c As New Collection
Dim o
For Each o In Selection.Tables
c.Add o
Next
Dim t As Table
For Each t In c
TransposeTable t
Next
End Sub
Sub TransposeTable(t As Table)
If t Is Nothing Then
Exit Sub
End If
Dim original_rows As Integer
original_rows = t.Rows.Count

Dim original_cols As Integer
original_cols = t.Columns.Count

Dim diagonal_count As Integer
diagonal_count = IIf(original_rows original_cols, original_rows,
original_cols)

' increase size
Do While t.Rows.Count diagonal_count
t.Rows.Add
Loop
Do While t.Columns.Count diagonal_count
t.Columns.Add
Loop
' add a row to hold values as they are shuffled.
t.Rows.Add

Dim j As Integer
Dim k As Integer
For k = 1 To diagonal_count
For j = k + 1 To diagonal_count
Call TableCellSwap(t, k, j, j, k)
Next
Next

' decrease size
Do While t.Rows.Count original_cols
t.Rows(t.Rows.Count).Delete
Loop
Do While t.Columns.Count original_rows
t.Columns(t.Columns.Count).Delete
Loop
End Sub
Sub TableCellMove(sourceTable As Table, sourceRow As Integer, sourceCol As
Integer, destTable As Table, destRow As Integer, destCol As Integer)
sourceTable.Cell(sourceRow, sourceCol).Select
Selection.Cut

destTable.Cell(destRow, destCol).Select
Selection.Paste
End Sub
Sub TableCellSwap(sourceTable As Table, sourceRow As Integer, sourceCol As
Integer, destRow As Integer, destCol As Integer)
Call TableCellMove(sourceTable, destRow, destCol, sourceTable,
sourceTable.Rows.Count, 1)
Call TableCellMove(sourceTable, sourceRow, sourceCol, sourceTable,
destRow, destCol)
Call TableCellMove(sourceTable, sourceTable.Rows.Count, 1,

sourceTable,
sourceRow, sourceCol)
End Sub


"Tesla" wrote:

Yes, there is. It involves a small macro that the vendor does not ship

with
the product. I am sorry that this forum danced around the issue and gave

you
no good advice.

This is a complete solution, which handles multiple tables selected, of

any
size, even with embedded OLE objects in the cells, and keeps the

original
formatting of the table. I worked Equations objects successfully in

them.

Do not panic with the seemingly chaotic dance of tables and selections

in
the document during processing, it all works nicely.

Here it is:


see version 2 above.