Consulting

Results 1 to 12 of 12

Thread: Solved: Stubborn Styles (How To Remove Them?)

  1. #1
    VBAX Regular
    Joined
    Dec 2006
    Posts
    10
    Location

    Solved: Stubborn Styles (How To Remove Them?)

    Hi All

    This is a tricky one. I have a file which has accumulated a number of styles in it (200+). I have managed to remove them all, but there are some remaining which I can't fgure out how to remove. Any advice?

    File Attached.

  2. #2
    VBAX Regular
    Joined
    Dec 2006
    Posts
    10
    Location
    So obviously my wording is a little off. I have removed most of them, not all.

  3. #3
    Moderator VBAX Master geekgirlau's Avatar
    Joined
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,464
    Location
    They're stubborn alright

    I tried looping through the styles and deleting all but a couple of specific styles (such as Normal) - most gave me no error messages, but it didn't delete any of the styles either!

    I don't know what to suggest here, but I can't think of another way to remove them - sorry!

  4. #4
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    This might have something to do with it:
    [vba]Sub a()
    MsgBox ActiveWorkbook.Styles.Count & " Styles"
    MsgBox ActiveWorkbook.Names.Count & " Defined Named Ranges"
    End Sub[/vba]
    I get 29 Styles and 51 Named Ranges.
    I can remove the named ranges with this from one of Jakes kb entries:
    [vba]
    Sub RemNamedRanges()
    Dim nm As Name
    For Each nm In ActiveWorkbook.Names
    nm.Delete
    Next
    End Sub

    [/vba]
    But I can't get this to work on Styles:
    [vba]Sub RemStyle()
    Dim st As Style
    For Each st In ActiveWorkbook.Styles
    st.Delete
    Next
    End Sub[/vba]
    I think you might be better off to copy the sheets to a new workbook..
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  5. #5
    Moderator VBAX Master geekgirlau's Avatar
    Joined
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,464
    Location
    I think you'll find if you copy the sheet, the style goes along for the ride ...

  6. #6
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    I hadn't tried it but it appears that you are correct Anne...? I never use styles so I'm kinda at a loss..
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  7. #7
    Moderator VBAX Master geekgirlau's Avatar
    Joined
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,464
    Location
    Untested, but maybe you could copy the cells and do a paste formula. You can't paste formats as this copies the style. I guess it depends on how badly you want to get rid of the styles versus how much time it will take to reformat the workbook ...

  8. #8
    VBAX Regular
    Joined
    Dec 2006
    Posts
    10
    Location
    Thanks for all your help so far. Reformatting the workbook would take days so I'd rather leave the stubborn styles behind than reformat the workbook. Its almost as if this is a bug in excel.

  9. #9
    VBAX Contributor Ivan F Moala's Avatar
    Joined
    May 2004
    Location
    Auckland New Zealand
    Posts
    185
    Location
    After removing named ranges ....
    Try saving as Html file and then back again


    see atttached
    Kind Regards,
    Ivan F Moala From the City of Sails

  10. #10
    VBAX Contributor Ivan F Moala's Avatar
    Joined
    May 2004
    Location
    Auckland New Zealand
    Posts
    185
    Location
    Sorry ... just in case .... do this on a Back up
    Kind Regards,
    Ivan F Moala From the City of Sails

  11. #11
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Saving it as html and back did work....I would never have thought to do that.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  12. #12
    VBAX Regular
    Joined
    Dec 2006
    Posts
    10
    Location
    May the excel Gods bless you. A great solution which preserves all existing used styles, but also copies the normal template of styles back into the workbook. I just hope no serious functionality is lost through saving to HTML and back again. Thanks again.

Posting Permissions

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