使用VBA宏识别项目符号列表的样式类型

时间:2019-07-02 16:52:26

标签: xml vba ms-word

我必须编写一个VBA宏来识别和删除已应用于项目符号列表中项目符号的样式类型。

在下面的document.xml部分中,我们使用了样式类型为“斜体”的项目符号。

<w w:rsidR="000450E5" w:rsidRPr="00A4560A" w:rsidRDefault="000450E5" w:rsidP="0009336F">
    <w:pPr>
        <w:pStyle w:val="ListBullet"/>
            <w:rPr>
            <w:i/>
            <w:lang w:val="es-ES"/>
        </w:rPr>
    </w:pPr>
    <w:r w:rsidRPr="00A4560A">
        <w:rPr>
            <w:lang w:val="es-ES"/>
        </w:rPr>
        <w:t xml:space="preserve">el marco legislativo y </w:t>
    </w:r>

在上面的示例中,<w:i/>是斜体样式。 因此,与添加了“斜体”样式类型的项目符号关联的document.cxml代码类似于:

<tps:liFormat><tps:style type="italic">—<tps:t/></tps:style></tps:liFormat>

我需要做的是,创建一个VB宏,以从文档中删除应用于项目符号的那些标签。

下面是我的代码。 我只是能够识别项目符号列表。我仍然找不到方法来检查应用的样式类型。

Public Sub main()
    Dim objDocument As Word.Document
    Dim objParagraph As Word.Paragraph

    Set objDocument = Word.ActiveDocument

    For Each objParagraph In objDocument.Paragraphs
        If objParagraph.Range.ListFormat.ListType = WdListType.wdListBullet Then
            If objParagraph.Range.ListFormat.StyleType = 'Italic' then  //Is there something like thid?
            //remove to set to normal
            End If
        End If
    Next objParagraph

End Sub

有人可以帮助我识别和删除添加到项目符号中的样式类型吗? 预先谢谢你。

1 个答案:

答案 0 :(得分:1)

以下代码查找具有ListBullet样式的每个段落,然后将范围定义为段落末尾的段落标记,然后删除斜体。段落标记存储更改项目符号的斜体格式。

For Each objParagraph In objDocument.Paragraphs
    Set objRange = objParagraph.Range
    If objRange.ListFormat.ListType = wdListBullet Then
        objRange.Collapse Direction:=wdCollapseEnd
        objRange.MoveStart Unit:=wdCharacter, Count:=-1
        objRange.Font.Italic = False
    End If
Next objParagraph