none
validate numbered list in Word RRS feed

  • Question

  • I wanted to validate numbering in word document using macro, if numbering is correct in sequence, and not missing anything in sequence, ex: 1. 2. and if 4. missing is 3. and same in inner level as well, here i was facing issue, first level can be anything and subsection numbering also can be anything! 

    it can start from number, alphabets, or roman numbers as well.





    Please suggest the macro or sample code would be of great help.

    Thanks,

    Regards,

    Hemal
    • Edited by Hemal Kotak Tuesday, March 11, 2014 5:42 PM
    Tuesday, March 11, 2014 5:42 PM

All replies

  • This would be far easier to manage if you employed Word list-level numbering with a suitable numbering structure. That way, the problem won't arise. No macros required.

    Cheers
    Paul Edstein
    [MS MVP - Word]

    Wednesday, March 12, 2014 4:50 AM
  • Hi Hemal,

    If there is any list not start with one, it would be a separate list.

    What I thought is to find the list which is not started with one. Then numbered the list according to the last list.

    Here is a sample for your reference:

    Sub AutoNumbering()
        Dim list As Word.list
        Dim i As Integer
    
        For i = 1 To ActiveDocument.Lists.Count
            Set list = ActiveDocument.Lists(i)
            list.Range.Select
            If list.Range.ListFormat.ListValue > 1 And i > 1 Then
                ActiveDocument.ListTemplates.Add (False)
                With ActiveDocument.ListTemplates(ActiveDocument.ListTemplates.Count).ListLevels(1)
                    .NumberFormat = ActiveDocument.Lists(i - 1).Range.ListFormat.ListTemplate.ListLevels(1).NumberFormat
                    .NumberStyle = ActiveDocument.Lists(i - 1).Range.ListFormat.ListTemplate.ListLevels(1).NumberStyle
                    .StartAt = ActiveDocument.Lists(i - 1).CountNumberedItems + 1
                End With
            End If
        Next
    End Sub

    Because list.Range contains its sub-list, so it would only apply to the last list:

    You could loop all paragraphs in the list, find the incorrect item using

    list.ListParagraphs(index).Range.ListFormat.ListValue

    Another way is to append the wrong number list content to the last item of a list then delete current list. When we append the content to a list, the number would be correct.

    Hope this helps.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, March 12, 2014 10:35 AM
    Moderator
  • I am not proficient in macro, when I ran the above macro got some error,

    error Text:

    Run-time error '91':

    Object variable or With block variable not set

    I did try to put Dim and set statement, in with block but it did not work, please help.

    basically I wanted to highlight non following numbered list items, example text below.

    Text goes here as follows:

    1         Exhibit A, Part A (Sjdgjgjrgj) of the Agreement is amended to include the following:

    (2)     ABC

    (a)     ABCD 

    2         Exhibit A, Part B (Permitted Applications) of the Agreement is amended to include the following:

    (d)     Analytics: 

    3         Exhibit A, Part C (Delivery) of the Agreement is amended to include the following:

    (2)     Analytics

           

    (a)     ABCD:   

    4         Exhibit A, Part D (Fees) of the Agreement is amended to include the following:

    (2)     Analytics

    (a)     XYZ: 

    (b)     aaa

    (d)     hello world

    (e)     my world

    (f)      your world

    6         Capitalized terms used without definition have the meanings ascribed to them in the Agreement.

    7         All other terms of the Agreement remain in full effect.


    • Edited by Hemal Kotak Tuesday, March 25, 2014 3:50 AM
    Monday, March 24, 2014 12:34 PM
  • Hi Hemal,

    The code would not throw any issue.

    I paste the content you provided into a Word document, but they will not be any list, so the loop code would not work.

    Would you mind sharing a simple document through OneDrive for us to reproduce the issue?


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, March 25, 2014 8:09 AM
    Moderator
  • Set up numbering properly associated with styles and you shouldn't run into any problems with it (as Paul/macropod already suggested in his reply). See http://shaunakelly.com/word/numbering/numbering20072010.html.

    If you encounter problems with style-based numbering, you can always revert settings to those of the underlying list template by selecting a paragraph and pressing Ctrl+Q.


    Stefan Blom, Microsoft Word MVP

    Tuesday, March 25, 2014 9:05 AM