PDA

View Full Version : move all tables in a document



skaz
07-22-2016, 03:35 PM
Hi. I have a number of documents that contain varying numbers of tables. The tables are currently in the wrong location and need to be moved down 13 lines from their current position.

I'd like to create a macro that will find each table and move it. I've was able to create a macro that moves the first table but I'm not sure how to fix all tables.

The code I have is:


Dim myCells As Range
With ActiveDocument
Set myCells = .Range(start:=.Tables(1).Cell(1, 1).Range.start, _
End:=.Tables(1).Cell(5, 2).Range.End)
myCells.Select
Selection.Cut
Selection.MoveDown Unit:=wdLine, Count:=13
Selection.Paste
End With

I tried adding a "For Each Table in Active Document" line at the top, but that had unwanted results (too confusing to describe).
Can anyone suggest a fix for this?

Thanks in advance!

gmayor
07-22-2016, 09:05 PM
'Line' is a vague concept in Word, however assuming there are more than 13 'lines' between each table, the following should work

Sub Macro1()
Dim oTable As Table
Dim i As Long
With ActiveDocument
For i = .Tables.Count To 1 Step -1
Set oTable = .Tables(i)
oTable.Select
Selection.Cut
Selection.MoveDown Unit:=wdLine, Count:=13
Selection.Paste
Next i
End With
lbl_Exit:
Exit Sub
End Sub

skaz
07-23-2016, 02:02 PM
This solved the problem. Thank you for your help. It is much appreciated!