Results 1 to 9 of 9
  1. #1
    biallas
    Guest

    Obtaining the Outline level numbers of a Heading

    Does anyone know of a method or property or snippet of code to get the current outline level numbers (N.m.n) string given the Selection point other than brute force looping through all the paragraphs counting levels? Even if backing up to the previous heading paragraph to get the info would be much much faster than starting at the top.
    Secondly, it would be great to also know the page that paragraph is on.

    I'd like to build a summary table/list of where certain custom paragraphs occur in a document.
    Something like;
    Section Heading Requirement Page
    3.3.1 Screen
    Show_this 10
    Show_that 11

    The field "PAGE " inserts the current page # into the document but I see know method/property to get at it via VB code. Same for the "STYLEREF " field.

    Does one need to build up one's own big collections of this info?
    Thanks in advance
    Randy

  2. #2
    Silver Lounger Charles Kenyon's Avatar
    Join Date
    Jan 2001
    Location
    Sun Prairie, Wisconsin, Wisconsin, USA
    Posts
    2,048
    Thanks
    124
    Thanked 119 Times in 116 Posts

    Re: Obtaining the Outline level numbers of a Heading

    I only know that if your Outline numbering is attached to styles properly, you can find the level in the style definition. See <A target="_blank" HREF=http://www.mvps.org/word/FAQs/Numbering/WordsNumberingExplained.htm> Word's Numbering Explained by John McGhie</A> (mvps.org/word/FAQs/).
    Charles Kyle Kenyon
    Madison, Wisconsin

  3. #3
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Obtaining the Outline level numbers of a Heading

    Charles,

    The point about obtaining the outline numbering level via the style definition requires a little clarification, because you can only obtain it if the style has been set up a specific way.

    For example, if you looked at the style definition of a particular numbered style, you might see "Level 3, Outline Numbered" as part of the style definition - it's important to note that the "Level 3" here does not (always) refer to the level this style occupies in the outline numbering scheme.

    Rather, the Level 3 mentioned here refers to the "Outline Level" setting, which is set in the Modify>Paragraph dialog (can also be gotten to via Format>Paragraph). This Outline Level setting affects two things mainly: how paragraphs with this style will be added to a table of contents; how paragraphs with this style will be viewed when the Document Map feature is used.

    So, in theory you could have a style called Level 3, which has been linked to the 3rd level of an outline numbering list, and yet the "Outline Level" could be Level 1! - understanbly confusing; it's too bad MS didn't give these two different properties, two different names.
    So if you were setting up your own outline numbering list and attaching styles, you'd want to make sure to set the "Outline Level" to a level equivalent to that style's level in the outline numbering list (whew!)

    And to add an additional wrinkle: the above only comes into play if you are not using the built-in Heading styles as outline numbered styles - the built-in Heading styles have their "Outline Level" property pre-assigned, and you can't change that.

    So you can find the "Outline numbering level" via the "Outline Level" reading in the style definition, but only if the Heading style was used, or if you have manually set the outline levels to be equivalent to the outline numbering levels.

    Hope that makes sense. <img src=/S/crazy.gif border=0 alt=crazy width=15 height=15>

    Gary

  4. #4
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Obtaining the Outline level numbers of a Heading

    Randy,

    There doesn't appear to be any direct way to get the current number of an autonumbered paragraph - as you suggest, there are probably some brute force methods though.

    As to the relatively easy part:
    Selection.Information (wdActiveEndPageNumber)
    will give you the page number.

    As far as the mention of StyleRef, can you flesh out a little more what you need to do? It's probabe that there's no equivalent in VBA that is quite as elegant as the way a StyleRef fields works, but there still should be some way to manage it.

    Another relatively clumsy way that you could retrieve the number would be to copy it, and paste it as unformatted text, retrieve the number from that, and delete what was just pasted in (credit to Ian Saunders for that trick).

    Gary

  5. #5
    biallas
    Guest

    Re: Obtaining the Outline level numbers of a Heading

    Thank you gentlemen for your inputs. I have read a number of you two gurus posts.
    I was afraid I'd need to add a whole bunch of extra code to handle internal reference points and numbers. There must be some internal tables that have the info since inserting a new outline level updates other numbering so quickly. Too bad its not exposed to VB.
    Randy

  6. #6
    Neil Eaton
    Guest

    Re: Obtaining the Outline level numbers of a Heading

    Hi Randy,

    I also wanted to do this, and some of the answers to your question gave me a clue how to do it, so I thought I'd return the favour and send you the function I created to get the current heading number. The file is a VBA export file containing the function find_heading_number. Its pretty slow, but it does the job in all the cases I've tested so far. Let me know if it works for you.

    Neil Eaton
    Emsys Engineering

  7. #7
    biallas
    Guest

    Re: Obtaining the Outline level numbers of a Heading

    Thanks Neil,
    I'm on some other things now but I'll try it out when I get back to it in earnest again. You've shown me some new methods and properties to look at.
    Randy

  8. #8
    3 Star Lounger
    Join Date
    Mar 2001
    Location
    Pune
    Posts
    310
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Obtaining the Outline level numbers of a Heading

    Hi, Neil

    Could you also explain how I can import the attached .bas file into a template for usage? Sorry for asking something which may seem extremely obvious to you.

  9. #9
    Neil Eaton
    Guest

    Re: Obtaining the Outline level numbers of a Heading

    You can import it into VBA from the Visual Basic Editor (NOT WORD) screen using FILE/IMPORT. If you are not familiar with the Visual Basic Editor, then this program is not going to help you. It is a subroutine, not a stand-alone application.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •