• What is my active cursor position’s heading?

    Home » Forums » AskWoody support » Productivity software by function » MS Word and word processing help » What is my active cursor position’s heading?

    • This topic has 4 replies, 2 voices, and was last updated 10 years ago.
    Author
    Topic
    #499795

    Hi!,
    I want to figure out what is my active cursor position’s heading?

    Heading1
    Heading2
    Heading3a
    Bla bla bla bla bla bla bla.
    Bla bla bla bla bla bla bla.
    Heading3b
    Bla bla bla bla bla bla bla.
    Bla bla bla bla bla bla bla. Now I’m here…

    THE RESULT THAT I WANT TO KNOW.
    Yor active cursor position’s headings are: Heading 3b & Heading2 & Heading1.

    Viewing 2 reply threads
    Author
    Replies
    • #1503013

      It is possible to do this and the following link shows some code that points to how I would attempt it. I don’t have the time to do the code at the moment but the concept is basically to:
      1. Use outline promote (Alt-Shift-Left arrow) on an unnumbered paragraph in order to find out what heading level is the nearest preceding heading.
      2. Loop backwards through the headings to find successively higher outline levels

      http://www.msofficeforums.com/word/24974-numbered-outline-continuation-headings.html

      • #1503016

        I tried, but couldn’t get the active cursor position’s headings.
        Not levels but as text.

    • #1503092

      Try this then. It will probably fail miserably if the heading structure isn’t logically arranged (ie H1 followed by H2 followed by H3 etc)

      Code:
      Sub POC()
        Dim aRng As Range, iLev As Integer
        Dim str As String
        
        Set aRng = Selection.Range
        Selection.GoTo What:=wdGoToHeading, Which:=wdGoToPrevious, Count:=1
        iLev = Selection.Paragraphs(1).OutlineLevel
        str = "H" & iLev & ": " & Selection.Paragraphs(1).Range.Text & str
        For i = iLev - 1 To 1 Step -1
          Do Until Selection.Paragraphs(1).OutlineLevel = i
            Selection.GoTo What:=wdGoToHeading, Which:=wdGoToPrevious, Count:=1
          Loop
          str = "H" & i & ": " & Selection.Paragraphs(1).Range.Text & str
        Next i
        
        MsgBox str
        aRng.Select
        
      End Sub
    • #1503103

      Perfect!
      Thank you very much.

    Viewing 2 reply threads
    Reply To: What is my active cursor position’s heading?

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: