使用Excel VBA在Word中删除项目符号段落

时间:2019-02-27 02:41:22

标签: vba selection bullet

我在Word文档中包含以下文本:

...

g = open("name.txt",'w')      
lines.remove(rand)
g.write('\n'.join(lines))

如何使用VBA完全删除包含字符串Total Amount Owed: <<Payment>> Dates Mowed: • 2/6/2019 • 2/14/2019 • <<Mowing1>> 的行的文本和项目符号?

提前谢谢!

1 个答案:

答案 0 :(得分:1)

可以尝试

Sub test()
Dim Pg As Paragraph,PgTxt as String

    For Each Pg In ActiveDocument.Paragraphs
        If Not Pg.Range.ListFormat.List Is Nothing Then  'Process only bulleted list
        PgTxt = Pg.Range.Text
            If InStr(1, PgTxt, "<<Mowing1>>") > 0 Then
            Pg.Range.Delete
            End If
        End If
    Next
End Sub