The task is to assign the current heading to a Headings which is 1 level lower that the previous heading.
The problem is that the previous heading changes from section to section, depending on the document.
Currently I have the following:
'Setting a Temp Bookmark to come back to
ActiveDocument.Bookmarks.Add Name:="CurrentPosition", Range:=Selection.Range
'Going Back to the previous Heading
Selection.GoTo What:=wdGoToBookmark, Name:="PreviousHeading"
'Determining the current and assigning the next style
If Selection.Style = ActiveDocument.Styles("Heading 1") Then
NextHeadingStyle= ActiveDocument.Styles("Heading 2")
ElseIf Selection.Style = ActiveDocument.Styles("Heading 2") Then
NextHeadingStyle= ActiveDocument.Styles("Heading 3")
ElseIf Selection.Style = ActiveDocument.Styles("Heading 3") Then
NextHeadingStyle= ActiveDocument.Styles("Heading 4")
ElseIf Selection.Style = ActiveDocument.Styles("Heading 4") Then
NextHeadingStyle= ActiveDocument.Styles("Heading 5")
ElseIf Selection.Style = ActiveDocument.Styles("Heading 5") Then
NextHeadingStyle= ActiveDocument.Styles("Heading 6")
End If
'Going back to the new Heading
Selection.GoTo What:=wdGoToBookmark, Name:="CurrentPosition"
'Changing the Style accordingly
Selection.Style = NextHeadingStyle
As a test, something which i have tried is:
Selection.Style = wdStyleHeading4 - 1
This will then set the text to a "Heading 5"
What I would like is something like:
'Setting a Temp Bookmark to come back to
ActiveDocument.Bookmarks.Add Name:="CurrentPosition", Range:=Selection.Range
'Going Back to the previous Heading
Selection.GoTo What:=wdGoToBookmark, Name:="PreviousHeading"
NextHeadingStyle = Selection.Style
NextHeadingStyle = NextHeadingStyle - 1
'Going back to the new Heading
Selection.GoTo What:=wdGoToBookmark, Name:="CurrentPosition"
'Changing the Style accordingly
Selection.Style = NextHeadingStyle
If there a way to do this?