• Word 2010 Macro – Delete Styles with Same Names

    Home » Forums » AskWoody support » Productivity software by function » MS Word and word processing help » Word 2010 Macro – Delete Styles with Same Names

    Author
    Topic
    #490465

    I am trying to write a macro to delete styles from a document. I am drawing a blank on Friday afternoon so I thought I’d ask if anyone has something similar. I get documents that have been redlined using the Workshare DeltaView software. This hard codes redlining in the document using styles. There are about 15 styles, all beginning with “DeltaView”, that get inserted into the document. I wrote a macro to strip out the formatting so that the document is “clean”, but I also want to delete all the styles when my other macro is done. I assume I need something with a for next loop to delete all styles with names beginning with “DeltaView”, and maybe deal with an error if there are none, but I’m not sure how to scroll thru the styles to check if DeltaView is in the name. Any suggestions? Thanks!

    Viewing 0 reply threads
    Author
    Replies
    • #1405961

      Try the following:

      Code:
      Sub DeleteDVStyles()
          Dim s As Style
          On Error Resume Next
          For Each s In ActiveDocument.Styles
              If Left$(s.NameLocal, 9) = “DeltaView” Then
                  s.Delete
              End If
          Next
      End Sub
    Viewing 0 reply threads
    Reply To: Word 2010 Macro – Delete Styles with Same Names

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: