Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #6  
Old 04-22-2014, 04:57 PM
macropod's Avatar
macropod macropod is offline Macro to add captions to pictures inside word document Windows 7 32bit Macro to add captions to pictures inside word document Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,375
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
 

Tags
automatic figure caption



Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to add captions to pictures inside word document VBA to insert captions without appending to existing captions Marrick13 Word VBA 17 03-21-2023 07:51 PM
Macro to add captions to pictures inside word document Help formatting Pictures inside a Text Box in Word 2013 jstumbo87 Word 2 01-29-2014 12:07 PM
Macro to add captions to pictures inside word document Macro to read word document harishankar.selvaraju Excel Programming 1 06-14-2012 03:48 AM
Where we can find a Word document (docx file) that contains professional work inside? Jamal NUMAN Word 0 06-26-2011 09:57 AM
Captions and Figures Inside a Frame...RIDICULOUS MS hasn't developed a solution!!! stlsmiln Word 2 02-23-2010 02:15 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:13 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft