Restart List Numbering for Word Doc from Excel VBA

Home / excel / Restart List Numbering for Word Doc from Excel VBA

Question:
I have a spreadsheet which has a matrix, with text in the first column that gets implemented into a built Word document if there is an "X" in the cell in the same row as that line of text. From this, I make lists with headings, but am having trouble restarting the list after every heading.

Below is my code that attempts to restart the list. It returns no errors until the last line item before the End If (List Galleries). Can anyone help?
If Range("A" & X – 1).Value = "Heading" Then
With ListGalleries(wdNumberGallery).ListTemplates(1).ListLevels(1)
.NumberFormat = "(%1)"
.TrailingCharacter = wdTrailingTab
.NumberStyle = wdListNumberStyleLowercaseLetter
.NumberPosition = CentimetersToPoints(2)
.Alignment = wdListLevelAlignLeft
.TextPosition = CentimetersToPoints(2.63)
.TabPosition = wdUndefined
.ResetOnHigher = 0
.StartAt = 1
With .Font
.Bold = wdUndefined
.Italic = wdUndefined
.Strikethrough = wdUndefined
.Subscript = wdUndefined
.Superscript = wdUndefined
.Shadow = wdUndefined
.Outline = wdUndefined
.Emboss = wdUndefined
.Engrave = wdUndefined
.Allcaps = wdUndefined
.Hidden = wdUndefined
.Underline = wdUndefined
.Color = wdColorBlack
.Size = wdUndefined
.Animation = wdUndefined
.DoubleStrikeThrough = wdUndefined
.Name = ""
End With
.LinkedStyle = "SOWSubList"
End With
ListGalleries(wdNumberGallery).ListTemplates(1).Name = ""
objWord.ActiveDocument.Characters.Last.Select
Selection.Range.ListFormat.ApplyListTemplateWithLevel ListTemplate:= _
ListGalleries(wdNumberGallery).ListTemplates(1), ContinuePreviousList:= _
True, ApplyTo:=wdListApplyToWholeList, DefaultListBehavior:= _
wdWord10ListBehavior
End If
objWord.Selection.TypeParagraph ‘move to the next line


Answer:

Read more

Leave a Reply

Your email address will not be published. Required fields are marked *