Moving tables around in doc

P

PiaD

Hi -
I have a document template that has many unique tables. Is there a way that
a macro can be used to move a selected table before the previous table or
after the subsequent table? I would like the user to ultimately control the
order of their tabular info.

Regards,
Pia
 
D

Doug Robbins - Word MVP

To move the table in which the selection is located before the preceding
table, use:

Dim i As Long
Dim target As Range
With ActiveDocument
For i = 1 To .Tables.Count
If Selection.InRange(.Tables(i).Range) Then
Exit For
End If
Next i
.Tables(i).Range.Cut
Set target = .Tables(i - 1).Range
target.Start = target.Start - 1
target.Collapse wdCollapseStart
target.Paste
End With

To move it after the next table, use:

Dim i As Long
Dim target As Range
With ActiveDocument
For i = 1 To .Tables.Count
If Selection.InRange(.Tables(i).Range) Then
Exit For
End If
Next i
.Tables(i).Range.Cut
Set target = .Tables(i).Range
target.End = target.End + 1
target.Collapse wdCollapseEnd
target.Paste
End With

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top