View Single Post
 
Old 07-09-2016, 11:49 PM
DougMVP DougMVP is offline Windows 7 32bit Office 2010 32bit
Advanced Beginner
 
Join Date: Nov 2013
Posts: 50
DougMVP will become famous soon enough
Default

myHeadings(icount) just returns the element from the array, and has no connection to the paragraph in the document.

The following code will however do what you want:

Code:
Dim bkmarkname As String
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("Heading 5")
With Selection.Find
    Do While .Execute(FindText:="", MatchWildcards:=False, Forward:=True, Wrap:=wdFindStop) = True
        With Selection
            bkmarkname = Mid(.Range.Text, InStr(.Range.Text, "|") + 2, InStrRev(.Range.Text, "|") - InStr(.Range.Text, "|") - 2)
            ActiveDocument.Bookmarks.Add Trim(bkmarkname), .Range
            .Collapse wdCollapseEnd
        End With
    Loop
End With
Reply With Quote