Results 1 to 5 of 5
  1. #1
    winter
    Guest

    VBA bugs with Word outlines (Word 2k)

    Apart from the documented failure of .OutlineLevel to work when a document is in outline view there are various other problems:

    If a set of child paragraphs are collapsed under a parent, VBA reports the wrong style name for the parent with hidden sub paras. (A heading level too low).

    Changing to normal view might seem a solution here, except that in normal view you can not tell which paras are collapsed. Give each para an .ID and store its level in an array before entering outline view ? Well, this doesn't work either because another bug is that paras tend to return a null string in place of their .ID when the view.type is outline/master.

    How about getting the correct outline level by switching on legal numbering and counting the dots ? Well, how do you read prefixes of paras from VBA ? Haven't cracked this ...

    So my question is: has anyone found a way of reading the correct style name or outline level, from outline view, of a paragraph which has collapsed sub-paras ?

    Many thanks, f.w.

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

    Re: VBA bugs with Word outlines (Word 2k)

    f.w.,

    The lack of response would seem to indicate that no one frequenting this board has had to cope with this particular problem - your luck!

    As far as a possible workaround by reading paragraph numbering, AFAIK there's no way to do this directly with VBA, but if you don't mind messing with your document, you could:

    Select the relevant (numbered) paragraph. Then:
    <pre> Selection.Range.ListFormat.ConvertNumbersToText
    </pre>

    will convert the numbering to text.
    Count the dots
    Switch the text back to numbering with:
    <pre> Selection.Range.ListFormat.ApplyOutlineNumberDefau lt
    </pre>

    - I've no idea whether that last line is reliable in all circumstances but it seems to stand up to a quick test.

    Gary

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

    Re: Return Autonumber As String

    Here's a quick fleshing out of a procedure to return an autonumber as a string.
    To make it easier I've assumed the numbering is outline numbering, and that there is a tab character after the autonumber.
    No doubt there are a lot of useful applications this could be put to. <img src=/S/cool.gif border=0 alt=cool width=15 height=15>
    (On the other hand, this was one of those "really ought to have been in bed sleeping" type jobs, so I'm not sure it will stand up to the light of day!)

    <pre>Sub ReturnAutonumberAsString()
    'Gary Frieder Woody's Lounge VB/VBA Forum July 2001
    'Purpose: Return outline autonumber as string
    Dim rngSelRng As Range
    Dim strParaText As String
    Dim strNumber As String
    Dim lngNumCharCt As Long
    Set rngSelRng = Selection.Range
    If rngSelRng.ListFormat.ListType = wdListOutlineNumbering Then
    rngSelRng.ListFormat.ConvertNumbersToText
    strParaText = rngSelRng.Paragraphs(1).Range.Text
    lngNumCharCt = InStr(1, strParaText, vbTab)
    strNumber = Left(strParaText, lngNumCharCt)
    MsgBox "Paragraph is autonumbered: " & strNumber
    ActiveDocument.Undo
    End If
    Set rngSelRng = Nothing
    End Sub</pre>


  4. #4
    winter
    Guest

    Re: Return Autonumber As String

    Many thanks, Gary, for giving this some thought. .ConvertNumbersToText is certainly a good approach.

    What I have done for the moment is to <ul>[*]Switch to normal view[*]read all paras and their levels into an array of user defined types, using an algorithm to specify the parent and children of each para[*]switch back to outline view, match the paras now showing one by one to those in the array (strcomp on the text)[*]flag all paras in the array which no longer show up in the text as .hidden, and flag their parents as .collapsed.[/list]

    Lots of expensive string comparisons, and your method may well prove faster.

    Thanks again, f.w.

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

    Re: Return Autonumber As String

    The following, much much simpler solution is taken from an <A target="_blank" HREF=http://www.mvps.org/word/FAQs/Numbering/ListString.htm>article</A> by MS Word MVP Dave Rado - thanks to Charles Kenyon for posting the link.

    Public Sub ReturnAutonumberStringAndListLevel()
    'Thanks to Dave Rado - see:
    'http://www.mvps.org/word/FAQs/Numbering/ListString.htm
    MsgBox Selection.Paragraphs(1).Range.ListFormat.ListStrin g
    MsgBox Selection.Paragraphs(1).Range.ListFormat.ListLevel Number
    End Sub

Posting Permissions

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