View Single Post
 
Old 07-24-2019, 09:48 AM
gmaxey gmaxey is offline Windows 10 Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,617
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

What you are describing are not "sections." Provided your "Chapter 3. Car" is a paragraph with an outline level 1 e.g., Heading1. Then the following may work:

Code:
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
Dim oTbl As Table
Dim oRng As Range, oRngCap As Range
Dim strTitle As String
  For Each oTbl In ActiveDocument.Tables
    Set oRng = oTbl.Range
    Set oRngCap = oTbl.Range
    oRng.Collapse wdCollapseStart
    oRngCap.Collapse wdCollapseEnd
    Do
      oRng.MoveStart wdParagraph, -1
      oRng.End = oRng.Paragraphs(1).Range.End - 1
      strTitle = oRng.Text
    Loop Until oRng.Paragraphs(1).OutlineLevel = 1
    oRngCap.InsertCaption Label:="Table", TitleAutoText:="", Title:=" - " & strTitle, _
    Position:=wdCaptionPositionAbove, ExcludeLabel:=0
  Next
lbl_Exit:
  Exit Sub
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote