1
votes

I have to write a VBA macro to identify and delete style types that have been applied to the bullet symbol in a bulleted list.

In the below document.xml part, we have a bullet with style type 'italic' applied.

<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>

in above example, <w:i/> is the italic style. So the document.cxml code associated with the 'italic' style type added bullet is like :

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

What I need to do is, create a VB macro to remove those tags applied for bullets from the document.

Below is my code. I was just able to identify the bullet lists. I am still unable to find a way to check the style type applied.

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

Could anybody help me to identify and remove the style type added to the bullet.. Thank you in advance.

1
Try adding the list to the Watch List and look at the properties?pgSystemTester
I don't recognize the namespace in the second block of xml code tps. Is this Word Open XML from a standard docx file? IF not, what is it? w:i is not the name of any style - it's a direct formatting command and appears to have been applied by a user to the document, possibly via the Bullets dialog box. The name of the style is ListBullet and its definition would be found in the Styles.xml part of the docx zip file - you should inspect that. StyleType refers to whether a style is a character, paragraph, linked, etc. Style and is not relevant for this.Cindy Meister
@CindyMeister Sorry , my mistake. The second block is the .cxml file of the document. we have a document to document.cxml converter and it is the output for the '<w:i/>' tag in .cxml fileApsSanj
@CindyMeister "w:i is not the name of any style - it's a direct formatting command and appears to have been applied by a user to the document, " : can we identify this direct formatting using a VBA macro?ApsSanj

1 Answers

1
votes

The following code finds each paragraph with a ListBullet style, then defines a range as the paragraph mark at the end of the paragraph, then removes italic. The paragraph mark stores the italic formatting that changes the bullet.

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