View Single Post
 
Old 04-22-2014, 04:57 PM
macropod's Avatar
macropod macropod is offline Windows 7 32bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
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

Try running the following macro after the AddImageCaptionTables macro (you can call this one from that one):
Code:
Sub AddCaptionText()
Dim Tbl As Table, RngCell As Range, RngRef As Range, StrTxt As String
For Each Tbl In ActiveDocument.Tables
  Set RngCell = Tbl.Range.Cells(Tbl.Range.Cells.Count).Range
  With RngCell
    .End = .End - 1
    .Collapse wdCollapseEnd
    If .Style = "Caption" Then
      Set RngRef = .Paragraphs.Last.Next.Next.Range
      With RngRef
        .End = .End - 1
        If .Fields.Count = 1 Then
          If .Fields(1).Type = wdFieldIndexEntry Then
            StrTxt = Trim(Replace(Replace(.Fields(1).Code.Text, "XE ", _
              vbNullString, , , vbTextCompare), Chr(34), ""))
            With RngCell
              .Text = ": " & StrTxt
              .Collapse wdCollapseEnd
              .FormattedText = RngRef.FormattedText
            End With
            .Paragraphs.First.Range.Delete
          End If
        End If
      End With
    End If
  End With
Next
End Sub
Note: With this code, your Index references are moved into the tables so they stay together.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote