A docx generated by a Word add-in from multiple separate docx files in a remote database contains for some reason multiple multi-level lists of the same list style. The consequence is that the numbering does not continue properly through the document. For example:
Heading 1 //wdContinueDisabled
Heading 2 //wdContinueList
Heading 1 //wdResetList
Heading 1 //wdResetList
From what I understand, Word creates a new list of the same list style every time when the numbering is restarted (i.e., the ListFormat.CanContinuePreviousList
method returns wdResetList
). Therefore, these resets should be removed and the only way that seemed to achieve this was by calling the ListFormat.ApplyListTemplate
method and setting the ContinuePreviousList
parameter to True
.
Therefore, I wrote a VBA macro that is supposed to loop through all paragraphs of all the lists with, say, list style “Foo”:
'variable declarations omitted for brevity
Set doc = ActiveDocument
Set lists = doc.lists
Set lt = doc.Styles("Foo").ListTemplate
For Each list In doc.lists
If list.StyleName = "Foo" Then
For Each par In list.ListParagraphs
par.Range.ListFormat.ApplyListTemplate lt, True, wdListWholeList
Next
End If
Next
However, this code does not produce any effect at all as all the numbering stays as it was. I would expect, however, that calling the ApplyListTemplate
method would set the wdContinue
enum to wdContinueList
.
Does anyone see what am I missing here and how I could turn the numbering into the following?
Heading 1 //wwdContinueDisabled
Heading 2 //wdContinueList
Heading 3 //wdContinueList
Heading 4 //wdContinueList