Results 1 to 7 of 7
  1. #1
    3 Star Lounger
    Join Date
    Apr 2001
    Location
    Levin, Manawatu-Wanganui, New Zealand
    Posts
    324
    Thanks
    9
    Thanked 28 Times in 26 Posts

    Paragraph as a list item (Word 2k xp)

    Greetings to the lounge
    I am fiddling about trying to ascertain which list a paragraph is associated with.
    I must confess to being bamboozled by the object model here.

    I think my little snippet does what I want (nearly) and your comments would be most welcome.

    -----------------------------------------------------
    Sub showlistMembership()
    Dim lst As ListParagraphs
    For i = 1 To ActiveDocument.Lists.Count
    Set lst = ActiveDocument.Lists(i).Range.ListParagraphs
    'MsgBox (lst.Count)
    For Each para In lst 'ActiveDocument.Paragraphs
    If Selection.Range.ListFormat.ListType > 0 _
    And Selection.Range.ListFormat.ListType < 7 Then
    MsgBox ("This paragraph is in list " & Format$(i))
    End If
    Next
    Next
    End Sub

    ----------------------------
    Now if I could only determine the paragraph number relative to the entire document I am nearly home.
    cheers
    Geof

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Paragraph as a list item (Word 2k xp)

    You asked a similar question in the Word forum in <post#=262353>post 262353</post#>. You haven't reacted to my reply there.

    The code you post here is not clear. You loop through the paragraphs of each list, but you don't do anything with it. Within the loop, you check the list type for the selection, not for the loop index.

    Do you want to determine something for the currently selected text, or something else? And can you explain what you want to accomplish?

  3. #3
    3 Star Lounger
    Join Date
    Apr 2001
    Location
    Levin, Manawatu-Wanganui, New Zealand
    Posts
    324
    Thanks
    9
    Thanked 28 Times in 26 Posts

    Re: Paragraph as a list item (Word 2k xp)

    Hi Hans
    Thanks for the two replies
    -----
    If the text is selected: Selection.Paragraphs(1).Range.ListFormat.ListTempl ate
    If you have defined your own range MyRange: MyRange.ListFormat.ListTemplate
    ----------------
    The goal is to produce a report identifying which paragraphs are elements in each list.

    I think my strategy should be to loop through the paragraphscollection identifying any list elements. IF a list element then establish which listtemplate it belongs.
    Sor of like this ...

    For each apara in activedocument.paragraphs
    paranumber = paranumber+1
    if paraNumber is a list item (test for listtemplate number then)
    write para number & list number to text file
    end if
    next


    Cheers

    Geof

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Paragraph as a list item (Word 2k xp)

    Geof,

    Here is a macro that does more or less what you ask, but I fear that you will find it of limited value. It lists the paragraphs in the active document that are part of a list in a new document. You can add code to save this new document as a text file.

    Sub ListLists()
    Dim i As Long
    Dim j As Long
    Dim lt As Long
    Dim lst As List
    Dim docActive As Document
    Dim docNew As Document

    Set docActive = ActiveDocument
    Set docNew = Documents.Add

    For i = 1 To docActive.Paragraphs.Count
    lt = docActive.Paragraphs(i).Range.ListFormat.ListType
    If lt > wdListNoNumbering Then
    Set lst = docActive.Paragraphs(i).Range.ListFormat.List
    For j = 1 To docActive.Lists.Count
    If lst.Range = docActive.Lists(j).Range Then
    docNew.Range.InsertAfter "Para " & i & vbTab & "List " & j & _
    vbTab & ListTypeName(lt) & vbCr
    End If
    Next
    End If
    Next i

    ' Cleaning up
    Set lst = Nothing
    Set docNew = Nothing
    Set docActive = Nothing
    End Sub

    ' Utility function to show list type name

    Function ListTypeName(lt As Long) As String
    Select Case lt
    Case 1
    ListTypeName = "wdListListNumOnly"
    Case 2
    ListTypeName = "wdListBullet"
    Case 3
    ListTypeName = "wdListSimpleNumbering"
    Case 4
    ListTypeName = "wdListOutlineNumbering"
    Case 5
    ListTypeName = "wdListMixedNumbering"
    Case 6
    ListTypeName = "wdListPictureBullet"
    End Select
    End Function

  5. #5
    3 Star Lounger
    Join Date
    Apr 2001
    Location
    Levin, Manawatu-Wanganui, New Zealand
    Posts
    324
    Thanks
    9
    Thanked 28 Times in 26 Posts

    Re: Paragraph as a list item (Word 2k xp)

    Thank you very much Hans
    I have played around with your suggestion and can honestly say I have learned a lot from your suggestions.
    Your efforts and assistance are really appreciated.

    Geof

  6. #6
    3 Star Lounger
    Join Date
    Apr 2001
    Location
    Levin, Manawatu-Wanganui, New Zealand
    Posts
    324
    Thanks
    9
    Thanked 28 Times in 26 Posts

    Re: Paragraph as a list item (Word 2k xp)

    Hello Hans
    THe big loop was a bit of a beast, but it gave me a few more insights.
    I have split it into a couple of functions ...
    example below

    Function GetListNumber()
    Dim j As Long
    Dim lst As List

    Set rgPara = Selection.Range.Paragraphs(1).Range

    Set lst = rgPara.ListFormat.List
    For j = 1 To ActiveDocument.Lists.Count
    If lst.Range = ActiveDocument.Lists(j).Range Then
    GetListNumber = j
    'Debug.Print GetListNumber
    Set lst = Nothing
    Exit Function
    End If

    Next

    End Function

    It runs fine over a problem document 257 pages, 152 lists, many probably with broken links to styles.
    It is a real messy beast of a document that is the cumulative result of multiple authors, typists, reviewing, and two versions of MS Office, over probably 3 years. I might try and fix it but I guess I will start from scratch build a new template, redefine the styles etc ...

    And it works, even if a bit slowly.

    Do we know any tricks to speed things up ?

    Thank you very much for your help, as ever your insights are welcome.

    Geof

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Paragraph as a list item (Word 2k xp)

    I am sorry, I don't know how to speed this up; I think that you're essentially stuck with the loop; in a large, complicated document this will inevitably take time.

    Perhaps other Loungers will have suggestions for improvement <img src=/S/crossfingers.gif border=0 alt=crossfingers width=17 height=16>

Posting Permissions

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