Results 1 to 2 of 2
  1. #1
    3 Star Lounger
    Join Date
    Mar 2003
    Location
    Elkins Park, Pennsylvania, USA
    Posts
    325
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Outline Information (Word XP)

    Hi again.

    I'm working on a template for a very structured kind of document. By that, I mean that the headings (at least through level 3) are always the same, and are associated with certain outline levels. (In other words, it leverages Word's headings and outline levels right out of the box.)

    I'm writing a function that (hopefully) will either allow or not allow a user to perform a task, depending on where he is in this document. For example, if the cursor is underline the section "1. Reporting of Data" which is formatted with Heading 3, I'd like to permit a certain task to run, and to not permit it otherwise. In short, I'd like to be able (via VBA) to determine the nearest preceding heading under which the current selection lies. I have an old piece of code that does an Edit: Search, but I'd like something a little more elegant.

    Before I reinvent the wheel, does anyone know if Word VBA has something like that built in? I was checking out objects and collections having to do with Lists and ListLevels, but I'm not sure if that's what I want. (I'm not too familiar with Word's List collections, mostly because I've heard such scary things about them and haven't taken the time to break-and-learn.)

    Does anyone have any experience with this? Thanks for any help.
    <font face="Comic Sans MS">That's what you do in a herd; you look out for each other!</font face=comic> - Mike

  2. #2
    3 Star Lounger
    Join Date
    Apr 2004
    Location
    Boston, Massachusetts, USA
    Posts
    389
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Outline Information (Word XP)

    Hi Mesaka,

    <pre>Selection.Range.GoToPrevious(wdGoToHeading).P aragraphs.First.OutlineLevel
    </pre>


    Will give you the most recent heading level (1-9). If there's no heading between the selection and the start of the document, it returns 10.

    So if you've got different actions depending on heading level, you could use a Select Case statement:

    <pre>Select Case Selection.Range.GoToPrevious(wdGoToHeading).Paragr aphs.First.OutlineLevel
    Case 1
    ' do stuff
    Case 2
    ' do stuff
    ' etc, etc.
    End Select
    </pre>


    HTH,

Posting Permissions

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