Hi,
I am trying to determine which heading the selected text is under when the macro is executed.
Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("Heading 1"
With Selection.Find
.Text = "^p"
.Replacement.Text = ""
.Forward = False
.Wrap = False
.Format = True
End With
Selection.Find.Execute
Selection.HomeKey Unit:=wdLine, Extend:=wdExtend
The code above searches upward for the nearest paragraph marker with a Style name of Heading 1. It then highlights to the start of the line. By doing this the selection contains the heading without the paragraph marker. This is the end result that I am looking for...
However, the nearest heading above the selection may be any of the Heading styles. Thus I would like the code to search upward for the nearest paragraph marker with a style name that contains "Heading".
Any suggestions?
I am trying to determine which heading the selected text is under when the macro is executed.
Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("Heading 1"
With Selection.Find
.Text = "^p"
.Replacement.Text = ""
.Forward = False
.Wrap = False
.Format = True
End With
Selection.Find.Execute
Selection.HomeKey Unit:=wdLine, Extend:=wdExtend
The code above searches upward for the nearest paragraph marker with a Style name of Heading 1. It then highlights to the start of the line. By doing this the selection contains the heading without the paragraph marker. This is the end result that I am looking for...
However, the nearest heading above the selection may be any of the Heading styles. Thus I would like the code to search upward for the nearest paragraph marker with a style name that contains "Heading".
Any suggestions?