Results 1 to 3 of 3
  1. #1
    3 Star Lounger rcbjr2's Avatar
    Join Date
    Jan 2001
    Location
    Matthews, NC
    Posts
    279
    Thanks
    6
    Thanked 1 Time in 1 Post

    Word 2010 Macro - Delete Styles with Same Names

    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!

  2. #2
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts
    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

  3. #3
    3 Star Lounger rcbjr2's Avatar
    Join Date
    Jan 2001
    Location
    Matthews, NC
    Posts
    279
    Thanks
    6
    Thanked 1 Time in 1 Post
    Fantastic! Thank you very much!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •