In a Word document, if there are multiple tables with captions inserted below each table, sometimes you might want to move these captions from below to above the table. How can you efficiently handle such tasks in the quickest way possible?
Move table captions from below to above or vice versa in Word using VBA
Move table captions from below to above or vice versa in Word using VBA
To move all the table captions from below to above the table, you can utilize the following VBA code:
Press ALT + F11 to open the Microsoft Visual Basic for Application window.
Click Insert > Module and paste the following macro into the Module window.
Sub ReLabelDownToUpTables()
Dim I As Long
Dim xRngPre As Range
Dim xRngNext As Range
Application.ScreenUpdating = False
With ActiveDocument
For I = .Tables.Count To 1 Step -1
With .Tables(I).Range
Set xRngPre = .Characters.First.Previous.Characters.Last
xRngPre.Select
Set xRngNext = .Characters.Last.Next.Paragraphs.First.Range
xRngNext.Select
With xRngPre
.InsertBefore vbCr
.Style = xRngNext.Style
.Start = .End – 1
.End = .Start
End With
If Len(xRngNext.Text) > 1 Then
xRngNext.End = xRngNext.End – 1
xRngNext.Cut
xRngNext.Delete
xRngPre.Paste
Else
xRngNext.Delete
End If
End With
Next
End With
Application.ScreenUpdating = True
End Sub
Then press F5 to run this code, and all the table captions have been moved from below to above the table, see the screenshot:
Note: To move table captions from above to below each table, you can apply the following VBA code:
Sub ReLabelUpToDownTables()
Dim I As Long
Dim xRngPre As Range
Dim xRngNext As Range
Application.ScreenUpdating = False
With ActiveDocument
For I = .Tables.Count To 1 Step -1
With .Tables(I).Range
Set xRngNext = .Characters.First.Previous.Paragraphs.First.Range
xRngNext.Select
Set xRngPre = .Characters.Last.Next
xRngPre.End = xRngPre.End – 1
xRngPre.Select
With xRngPre
.InsertBefore vbCr
.Style = xRngNext.Style
.Start = .End – 1
.End = .Start
End With
If Len(xRngNext.Text) > 1 Then
xRngNext.End = xRngNext.End – 1
xRngNext.Cut
xRngNext.Delete
xRngPre.Paste
Else
xRngNext.Delete
End If
End With
Next
End With
Application.ScreenUpdating = True
End Sub
Insert multiple table, figure, or equation captions in a Word document at once:
Normally, you should insert table, figure, or equation captions for tables, figures, or equations one by one in a Word file. However, if you have the feature Multiple Captions of Kutools for Word, you can insert table, figure, or equation captions for all tables, figures, or equations at once as quickly as possible.