Results 1 to 12 of 12
  1. #1
    2 Star Lounger
    Join Date
    Dec 2007
    Posts
    179
    Thanks
    3
    Thanked 0 Times in 0 Posts

    VBA routine to delete all "garbage styles"; Lists; Issues to be aware of

    Hi all,

    I need to write a VBA routine to delete all "garbage styles". I am assuming you all know what I mean, but for example, all char chars ...

    Anybody know what is the full list of garbage styles so I can identify them?

    What issues do I have to be aware of when I delete them (each of them)?

    TIA

    -avraham

  2. #2
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts
    For char chars, see: http://homepage.hispeed.ch/cindymeis...p.htm#CharStyl
    I'm not sure what else you mean by 'garbage styles'.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  3. #3
    2 Star Lounger
    Join Date
    Dec 2007
    Posts
    179
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Thanks for the response, Cindy.

    >> I'm not sure what else you mean by 'garbage styles'

    Ummm ... some things that immediately come to my mind are ... you know when the following switches are turned ON in the AutoCorrect dialog box:

    - Preserve styles

    - Define styles based on your formatting

    And from Word Options, there is

    - Keep track of formatting

    So when you leave all those flags ON, that creates a tremedous amount of garbage styles. How do you get rid of them all...?

    And there is also something about the issue of before you delete a style, you must unlink it from other styles?

    -avraham
    Last edited by amakeler; 2012-07-22 at 11:42.

  4. #4
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts
    I take it, then, you mean those Style names that are followed by various character attributes. There is no "full list of garbage styles" in that sense - what you might have in a given document depends on what's been imported into that document and the definitions in that document can be entirely different from what you might find in another document. Furthermore, since those 'garbage' Styles have been created to reflect the actual document content, deleting them will mean that whatever content is using them will revert to to Normal Style, losing all other formatting in the process.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  5. #5
    2 Star Lounger
    Join Date
    Dec 2007
    Posts
    179
    Thanks
    3
    Thanked 0 Times in 0 Posts
    >> whatever content is using them will revert to to Normal Style, losing all other formatting in the process.

    Yes - for sure. Well, that's my client's problem.

    Unless I use some AI mechanism to map garbage styles to intended real good styles.

    -avraham

  6. #6
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts
    At its most basic, you could delete anything that isn't a built-in Style, using something like:
    Code:
    Sub CleanStyles()
    Dim oSty As Style
    With ActiveDocument
      On Error Resume Next
      For Each oSty In .Styles
        If oSty.Linked = True Then
          .Styles.Add Name:="TmpSty"
          oSty.LinkStyle = "TmpSty"
          .Styles("TmpSty").Delete
        End If
        If oSty.BuiltIn = False Then oSty.Delete
      Next
    End With
    End Sub
    Beyond that, determining what's a 'garbage' Style and what isn't becomes a matter of definition.

    As for 'mapping', that can entail a lot of effort given all the possibilities for fonts, point sizes, bold/italic, indenting, tabs, etc. You might do better to use Find/Replace to change any 'garbage' Styles in use to alternate 'good' Styles, then run the macro above (or a variation on it that preserves known good custom Styles as well as the built-in ones).
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  7. #7
    2 Star Lounger
    Join Date
    Dec 2007
    Posts
    179
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Thanks, Paul!

    -----------------------

    Sorry, earlier I meant to say "
    Thanks, Paul", instead of "Thanks, Cindy"....
    -a

  8. #8
    WS Lounge VIP
    Join Date
    Mar 2006
    Location
    Maryland, USA
    Posts
    690
    Thanks
    17
    Thanked 66 Times in 56 Posts
    If what you want to do is get rid of all direct formatting (everything after the plus sign after a style pane entry), select the whole document and press Ctrl+spacebar or, if the document has chracter styles you want to keep, got to the style inspector and press the button for clear character formatting, which is separate from clear character style. I don't know if there are vba commands for these Word commands.

    Pam

  9. #9
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts
    Hi Pam,

    That will remove the formatting, but not the 'garbage' Style definitions.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  10. #10
    WS Lounge VIP
    Join Date
    Mar 2006
    Location
    Maryland, USA
    Posts
    690
    Thanks
    17
    Thanked 66 Times in 56 Posts
    Well, "garbage styles" is way too broad since it could mean any unwanted styles, unlinked (char) styles, multiple style alias style names, and showing a style plus its direct paragraph, font, and bullet & numbering formatting in the styles pane as if it were a separate style. For the last one, when you clear the formatting, you clear the style + formatting entry from the styles list.

  11. #11
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts
    Hi Pam,

    I'm fully aware of that, as you'll see from my previous posts, particularly the one with the macro, where I said:
    determining what's a 'garbage' Style and what isn't becomes a matter of definition.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  12. #12
    WS Lounge VIP
    Join Date
    Mar 2006
    Location
    Maryland, USA
    Posts
    690
    Thanks
    17
    Thanked 66 Times in 56 Posts
    And I read & fully agreed with what you wrote. My response was limited to styles plus formatting ("If what you want to do is get rid of all direct formatting (everything after the plus sign after a style pane entry))". I don't think your response covers the possibility that the style itself might be wanted.

Posting Permissions

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