![]() |
|
#5
|
|||
|
|||
|
Actually Andrew's code is cleaner ;-). If you really do only want to use a specific heading to fix the table captions (e.g., Heading 1), here is a version which combines his method and mine:
Code:
Sub ScratchMacro()
Dim oTbl As Table, oRngHeading As Range
Dim lngLevel As Long
lngLevel = 1 'This means only Heading 1 Style is used to define table titles.
For Each oTbl In ActiveDocument.Tables
Set oRngHeading = oTbl.Range.GoTo(What:=wdGoToHeading, Which:=wdGoToPrevious, Count:=1).Paragraphs(1).Range
Do Until oRngHeading.Paragraphs(1).OutlineLevel = lngLevel
Set oRngHeading = oRngHeading.GoTo(What:=wdGoToHeading, Which:=wdGoToPrevious, Count:=1).Paragraphs(1).Range
Loop
oRngHeading.MoveEnd Unit:=wdCharacter, Count:=-1
oTbl.Range.InsertCaption Label:="Table", Title:=" - " & oRngHeading.Text, Position:=wdCaptionPositionBelow, ExcludeLabel:=0
Next
lbl_Exit:
Exit Sub
End Sub
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Automatic locking section of document AFTER text typed
|
lou1990lou | Word VBA | 2 | 01-20-2019 02:39 PM |
Automatic table of contents for just one section of document?
|
seanspotatobusiness | Word | 2 | 02-06-2017 07:13 AM |
| section page numbers reverting to following on from previous section after generating index | cloudtrapezer | Word | 1 | 06-25-2015 01:16 AM |
Generating Print Labels Dynamically Based on SQL Server
|
expinch | Word | 1 | 11-26-2014 10:05 PM |
| Automatic table of figures includes one of the figures, not just the caption - help! | sarahlt | Word | 1 | 09-28-2014 09:34 AM |