View Single Post
 
Old 10-21-2017, 02:26 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,465
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

It's still not clear from your post whether your Headlinestyle Styles are just Heading Styles under another name. If so, try the following:
Code:
Sub IndexUpdater()
Application.ScreenUpdating = False
Dim i As Long, strStl As String, strRef As String, Rng As Range
Set Rng = Selection.Range
Set Rng = Rng.GoTo(What:=wdGoToBookmark, Name:="\HeadingLevel")
With Rng
  For i = 1 To .Fields.Count
    With .Fields(i)
      If .Type = wdFieldIndexEntry Then
        If .Code.Fields.Count = 1 Then
          With .Code.Fields(1)
            If .Type = wdFieldStyleRef Then
              strStl = .Code.Paragraphs(1).Style
              strRef = Split(Split(.Code.Text, "STYLEREF")(1), Chr(34))(1)
              If strRef <> strStl Then .Code.Text = Replace(.Code.Text, strRef, strStl)
            End If
          End With
        End If
      End If
    End With
  Next
End With
Application.ScreenUpdating = True
End Sub
With this code, the heading that contains the insertion point or selection, plus any subordinate headings and text. If the current selection is body text, the '\HeadingLevel' bookmark includes the preceding heading, plus any headings and text subordinate to that heading.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote