Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #3  
Old 07-24-2019, 03:28 PM
Guessed's Avatar
Guessed Guessed is offline Generating automatic caption for table based on document section Windows 10 Generating automatic caption for table based on document section Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,176
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

Greg's code always gives you the above Heading 1 text. If you wanted the nearest preceding heading of any level the code could be
Code:
Sub ScratchMacro()
  Dim oTbl As Table, oRng As Range, rngHead As Range, strTitle As String
  For Each oTbl In ActiveDocument.Tables
    Set oRng = oTbl.Range
    Set rngHead = oRng.GoTo(What:=wdGoToHeading, Which:=wdGoToPrevious, Count:=1).Paragraphs(1).Range
    rngHead.MoveEnd Unit:=wdCharacter, Count:=-1
    strTitle = rngHead.Text
    oTbl.Range.InsertCaption Label:="Table", Title:=" - " & strTitle, Position:=wdCaptionPositionAbove, ExcludeLabel:=0
  Next
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Generating automatic caption for table based on document section Automatic locking section of document AFTER text typed lou1990lou Word VBA 2 01-20-2019 02:39 PM
Generating automatic caption for table based on document section 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 automatic caption for table based on document section 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

Other Forums: Access Forums

All times are GMT -7. The time now is 12:44 AM.


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