Share via

Delete custom styles

Anonymous
2013-06-26T15:10:49+00:00

Hi All,   I have picked-up some customers tyles that I want to delete it with VBA but get an error message.   Although the styles exists because "? activeworkbook.styles(1).Name" returns "LÓÄþÍN^NuNVþˆHÁ(n"   activeworkbook.styles(1).delete gives the error Run-time error 1004, delete method of style class failed.   I suspect an Excel 2003 that has meshed up my workbook. Do I have to use another method to delete XL 2003 styles?   Is there a work-around to force delete this style?   Wkr,   JP Ronse

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

4 answers

Sort by: Most helpful
  1. Anonymous
    2013-06-27T10:02:01+00:00

    Hi All,

    Just to inform you that I could removed the unwanted custom styles. Because it wasn't possible from within Excel or with VBA, I had to edit the XML part:

    1. Made a copy of my file and renamed the extension to .zip
    2. Open the zip file with 7-zip
    3. Export of styles.xml (in folder xl)
    4. Open styles.xml with XML Notepad and remove the unwanted styles (cellstyles)
    5. Delete styles.xlm from archive.
    6. Import the edited styles.xml
    7. Closed the archive and rename the extension back to the original (xlsx or xlsm)

    Problem solved.

    Wkr,

    JP Ronse

    Was this answer helpful?

    7 people found this answer helpful.
    0 comments No comments
  2. Anonymous
    2013-06-27T10:48:10+00:00

    Glad you found a solution.

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2013-06-26T19:15:26+00:00

    Hi Gary,

    Tried your suggestion but had the same error. Other ideas are welcome.

    I saw also post about deleting a style in XML. How to do this.

    I had a look in the XML but see anything wrong or suspected.

    Wkr,

    JP Ronse

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2013-06-26T15:33:21+00:00

    Try to delete it by Name:

    Sub dural()

    Dim sty As Style

    For Each sty In ActiveWorkbook.Styles

    If sty.Name = "Unnecessary" Then

    sty.Delete

    MsgBox "Unnecessary deleted"

    End If

    Next

    End Sub

    Was this answer helpful?

    0 comments No comments