Forum Discussion
VBA - Range to include numbered lists
Tom_Griffith With the following code, if there are no numbered lists, the code will be terminated after the .ConvertNumberstoText
Dim blnConvert As Boolean
With ActiveDocument
.UndoClear
.Save
.ConvertNumbersToText
blnConvert = .Saved
If blnConvert = True Then
Exit Sub
End If
Selection.Range.Text = Replace(Selection.Range.Text, vbTab, " ")
'do what you want to
.Undo (3) 'may need to replace 3 to allow for other changes that you make
End With- TomGriffith3Oct 13, 2023Brass Contributor
Doug_Robbins_Word_MVP thanks so much. I had to jump off this for a little while and came back to it the other day. I took your suggestion and kind of do something similar, because if there are no numbered lists, there still is processing to be done.. I parse all the paragraphs in the doc, if gwordDoc.Paragraphs(i).Range.ListFormat.ListType=3 is encountered, set the boolean blnConvert to true. If blnConvert=true, do the gWordDoc.ConvertNumbersToText, do the stuff then call the gWordDoc.Undo.
Otherwise, if gwordDoc.Paragraphs(i).Range.ListFormat.ListType=3 is not encountered parsing the gWordDoc paragraphs, just do the stuff.