word中可以给段落添加列表项,自动添加的列表项对象是List对象。如果在文档的不同位置应用不同的列表项,这些列表项对象就组合了Lists集合对象。如果要访问某个List对象中的具体某个列表项所代表的段落,可以使用ListParagraphs属性访问。
如以下代码是遍历第一个列表项中的每个列表项数字所表示的段落,判断是否包含数字,如果包含数字则删除该段落。
Sub QQ1722187970()
Dim oDoc As Document
Set oDoc = Word.ActiveDocument
Dim oList As List
Set oList = oDoc.Lists(1)
Dim oP1 As Paragraph
Dim oP2 As Paragraph
iLPC = oList.ListParagraphs.Count
For i = iLPC - 1 To 1 Step -1
'遍历两个数字列表项之间的段落内容
Set oP1 = oList.ListParagraphs(i)
Set oP2 = oList.ListParagraphs(i + 1)
Set oRng = oDoc.Range(oP1.Range.Start, oP2.Range.Start)
Debug.Print oRng.Text
If Not (oRng.Text Like "*[0-9]*") Then oRng.Delete
Next
'将最后一个列表项数字内容也判断一遍
iEnd = oDoc.Range.End
iLPC = oList.ListParagraphs.Count
Set oRng = oDoc.Range(oList.ListParagraphs(iLPC).Range.Start, iEnd)
If Not (oRng.Text Like "*[0-9]*") Then oRng.Delete
End Sub


发表评论