Get Word Document List Number Hierarchy

Discussion in 'Word VBA' started by crookie74@gmail.com, Feb 10, 2014.

  1. Guest

    I would like to be able to get out the full list number hierarchy of wherever I am in a document. So if i have

    1 Top Level text
    1.1 Second Level text
    (a)Third Level text item 1
    (b)Third Level text item 2

    and I have some text highlighted on the (b) line, I would like to build a string 1-1.1-(b)

    I relise i can get the "(b)" on its own by:
    Selection.Range.ListFormat.ListString
    or
    Selection.Paragraphs(1).Range.ListFormat.ListString

    but I dont know how to go from that to the next level up in the hierarchy ie 1.1

    Thanks in advance if anyone can help me.
     
    , Feb 10, 2014
    #1
    1. Advertisements

  2. Stefan Blom Guest

    What are you trying to accomplish? If you are creating a cross-reference,
    you can do so via the Cross-reference dialog box (References tab |
    Cross-reference). For "Reference type," choose "Numbered item." In the
    "Insert reference to" drop down, select "Paragraph number (full context)."
    The "full context" option will always include higher levels in the numbering
    hierarchy.

    --
    Stefan Blom
    Microsoft Word MVP




    <> wrote in message
    news:...
    > I would like to be able to get out the full list number hierarchy of
    > wherever I am in a document. So if i have
    >
    > 1 Top Level text
    > 1.1 Second Level text
    > (a)Third Level text item 1
    > (b)Third Level text item 2
    >
    > and I have some text highlighted on the (b) line, I would like to build a
    > string 1-1.1-(b)
    >
    > I relise i can get the "(b)" on its own by:
    > Selection.Range.ListFormat.ListString
    > or
    > Selection.Paragraphs(1).Range.ListFormat.ListString
    >
    > but I dont know how to go from that to the next level up in the hierarchy
    > ie 1.1
    >
    > Thanks in advance if anyone can help me.
     
    Stefan Blom, Feb 15, 2014
    #2
    1. Advertisements

  3. Guest

    Thanks Stefan. I know all about the cross-refernce box and elsewhere in my code I a using that the information in it, but doesn't help me for this. The cross-refernce information is poor and you have to mess around with numbers of spaces to find out what level things are at, which I have done. However For this bit of the code, wherever I am in my document, i need to know about the complete family list that I am inso that I can relate it back to the cross-reference. So as the example shows in my first post, knowing "(b)"doesn't help me in code to know where we are in the cross-refernce as there could be many nodes that start (b). Hence why I want to find the full family path of "(b)" so that I can key it back to the cross reference.

    However I have now managed to do this by writing a loop and using GoToPrevious to find out each parent level of where I am.

    On Saturday, 15 February 2014 19:04:07 UTC, Stefan Blom wrote:
    > What are you trying to accomplish? If you are creating a cross-reference,
    >
    > you can do so via the Cross-reference dialog box (References tab |
    >
    > Cross-reference). For "Reference type," choose "Numbered item." In the
    >
    > "Insert reference to" drop down, select "Paragraph number (full context)."
    >
    > The "full context" option will always include higher levels in the numbering
    >
    > hierarchy.
    >
    >
    >
    > --
    >
    > Stefan Blom
    >
    > Microsoft Word MVP
    >
    >
    >
    >
    >
    >
    >
    >
    >
    > <c> wrote in message
    >
    > news:...
    >
    > > I would like to be able to get out the full list number hierarchy of

    >
    > > wherever I am in a document. So if i have

    >
    > >

    >
    > > 1 Top Level text

    >
    > > 1.1 Second Level text

    >
    > > (a)Third Level text item 1

    >
    > > (b)Third Level text item 2

    >
    > >

    >
    > > and I have some text highlighted on the (b) line, I would like to builda

    >
    > > string 1-1.1-(b)

    >
    > >

    >
    > > I relise i can get the "(b)" on its own by:

    >
    > > Selection.Range.ListFormat.ListString

    >
    > > or

    >
    > > Selection.Paragraphs(1).Range.ListFormat.ListString

    >
    > >

    >
    > > but I dont know how to go from that to the next level up in the hierarchy

    >
    > > ie 1.1

    >
    > >

    >
    > > Thanks in advance if anyone can help me.
     
    , Feb 18, 2014
    #3
  4. Stefan Blom Guest

    "Full context" should give you just that: the complete reference, including
    all higher levels in the numbering scheme. Obviously, I'm missing something
    here.

    --
    Stefan Blom
    Microsoft Word MVP




    <> wrote in message
    news:...
    > Thanks Stefan. I know all about the cross-refernce box and elsewhere in my
    > code I a using that the information in it, but doesn't help me for this.
    > The cross-refernce information is poor and you have to mess around with
    > numbers of spaces to find out what level things are at, which I have done.
    > However For this bit of the code, wherever I am in my document, i need to
    > know about the complete family list that I am inso that I can relate it
    > back to the cross-reference. So as the example shows in my first post,
    > knowing "(b)" doesn't help me in code to know where we are in the
    > cross-refernce as there could be many nodes that start (b). Hence why I
    > want to find the full family path of "(b)" so that I can key it back to
    > the cross reference.
    >
    > However I have now managed to do this by writing a loop and using
    > GoToPrevious to find out each parent level of where I am.
    >
    > On Saturday, 15 February 2014 19:04:07 UTC, Stefan Blom wrote:
    >> What are you trying to accomplish? If you are creating a cross-reference,
    >>
    >> you can do so via the Cross-reference dialog box (References tab |
    >>
    >> Cross-reference). For "Reference type," choose "Numbered item." In the
    >>
    >> "Insert reference to" drop down, select "Paragraph number (full
    >> context)."
    >>
    >> The "full context" option will always include higher levels in the
    >> numbering
    >>
    >> hierarchy.
    >>
    >>
    >>
    >> --
    >>
    >> Stefan Blom
    >>
    >> Microsoft Word MVP
    >>
    >>
    >>
    >>
    >>
    >>
    >>
    >>
    >>
    >> <c> wrote in message
    >>
    >> news:...
    >>
    >> > I would like to be able to get out the full list number hierarchy of

    >>
    >> > wherever I am in a document. So if i have

    >>
    >> >

    >>
    >> > 1 Top Level text

    >>
    >> > 1.1 Second Level text

    >>
    >> > (a)Third Level text item 1

    >>
    >> > (b)Third Level text item 2

    >>
    >> >

    >>
    >> > and I have some text highlighted on the (b) line, I would like to build
    >> > a

    >>
    >> > string 1-1.1-(b)

    >>
    >> >

    >>
    >> > I relise i can get the "(b)" on its own by:

    >>
    >> > Selection.Range.ListFormat.ListString

    >>
    >> > or

    >>
    >> > Selection.Paragraphs(1).Range.ListFormat.ListString

    >>
    >> >

    >>
    >> > but I dont know how to go from that to the next level up in the
    >> > hierarchy

    >>
    >> > ie 1.1

    >>
    >> >

    >>
    >> > Thanks in advance if anyone can help me.

    >
     
    Stefan Blom, Feb 18, 2014
    #4
  5. Guest

    Maybe I'm missing something obvious, but I can't see "full context" is available to me unless im adding a cross-refernce to another range? In VBA, am I able to find the full context of any range ie something along the lines of:
    strMyString = Selection.Range.FullContext
    If so, can you tell me how to write that properly?
    My point is that I am not wanting to add a cross-reference, but I want to use the family structure of any range in the document to do some checking
     
    , Feb 24, 2014
    #5
  6. Stefan Blom Guest

    My thought was that you could use the cross-reference as a starting point
    when retrieving the full context. Perhaps there is a better way; I don't
    know. Since this group is low traffic these days, you may want to ask in the
    Word Developer forum at MSDN:

    http://social.msdn.microsoft.com/Forums/office/en-US/home?forum=worddev

    --
    Stefan Blom
    Microsoft Word MVP




    <> wrote in message
    news:...
    > Maybe I'm missing something obvious, but I can't see "full context" is
    > available to me unless im adding a cross-refernce to another range? In
    > VBA, am I able to find the full context of any range ie something along
    > the lines of:
    > strMyString = Selection.Range.FullContext
    > If so, can you tell me how to write that properly?
    > My point is that I am not wanting to add a cross-reference, but I want to
    > use the family structure of any range in the document to do some checking
     
    Stefan Blom, Mar 7, 2014
    #6
  7. KrystalSkul

    Joined:
    Jan 15, 2015
    Messages:
    1
    Likes Received:
    0
    Did anyone ever get an answer for this? I am trying to do the same thing.

    The reason for needing this is that I need to generate a separate document of certain noncontiguous selected paragraphs in the main document. I want the macro to paste the full context of the paragraph I am copying and pasting.
    Is there an easy way to do this, or do I have to trace back each list level and build a string that way?

    The full context information is obviously tracked in Word, but how do I access the full context paragraph number for a selected paragraph in VBA?

    I don't think there is a paste option that does this. So what is the variable that stores the full context paragraph number for cross references that insert the full context number. I want to store the value of this variable for use with the paragraph in the second document.
     
    KrystalSkul, Jan 15, 2015
    #7
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jpngrl
    Replies:
    0
    Views:
    94
    jpngrl
    Jan 28, 2005
  2. Jay Freedman
    Replies:
    3
    Views:
    232
    Avi Mak
    Jul 18, 2005
  3. jlp1782

    Hierarchy Sorting Macro

    jlp1782, Feb 6, 2006, in forum: Word VBA
    Replies:
    12
    Views:
    119
    jlp1782
    Feb 9, 2006
  4. john smith
    Replies:
    3
    Views:
    217
  5. Replies:
    1
    Views:
    140
    Shauna Kelly
    Jan 8, 2008
  6. avkokin
    Replies:
    3
    Views:
    85
    StevenM
    Aug 4, 2008
  7. Sardonic
    Replies:
    3
    Views:
    223
    Doug Robbins - Word MVP
    Nov 27, 2008
  8. Ricky Marek
    Replies:
    0
    Views:
    146
    Ricky Marek
    Oct 16, 2013
Loading...