Thread: [Solved] Move existing table captions
View Single Post
 
Old 09-04-2011, 02:37 AM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,527
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi bcarlier,

Based on what you've said, try:
Code:
Sub ReLabelTables()
Application.ScreenUpdating = False
Dim i As Long, oPrev As Range, oNext As Range
With ActiveDocument
  For i = .Tables.Count To 1 Step -1
    With .Tables(i).Range
      Set oPrev = .Characters.First.Previous.Characters.Last
      Set oNext = .Characters.Last.Next.Paragraphs.First.Range
      With oPrev
        .InsertBefore vbCr
        .Start = .End - 1
        .Style = oNext.Style
        .End = .Start
        If Len(oNext.Text) > 1 Then
          With oNext
            .End = .End - 1
            .Cut
            .Delete
          End With
          .Paste
        Else
          oNext.Delete
        End If
      End With
    End With
  Next
End With
Application.ScreenUpdating = True
End Sub
There's no error-checking - the code simply moves whatever paragraph follows each table to before the table.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote