Cannot Delete Cell Styles

mikeTRON

New Member
Joined
Sep 27, 2012
Messages
42
So I run this code to delete cell styles normally.

Code:
Option Explicit

Sub StyleKill()
'this is designed to clean all the cell styles out of a workbook because I prefer to use the DEFAULTS and any custom styles are put above the defaults
    
    'declare variables
    Dim styT As Style
    Dim intRet As Integer
    Dim count As Long
        
    'count how many styles there are, mostly for LOLz
    For Each styT In ActiveWorkbook.Styles
        count = count + 1
    Next styT
    
    'ask if you want to delete all styles (but it means all NON default styles)
    intRet = MsgBox("You have " & count & " styles to delete. Do you want to Delete?", vbYesNo)
        
        If intRet = vbYes Then
            On Error Resume Next ' error handling
                For Each styT In ActiveWorkbook.Styles
                    If Not styT.BuiltIn Then
                    MsgBox styT.Name
                        styT.IncludeProtection = False ' attempting to unlock the style BEFORE deleting but I am not sure it is working
                        styT.Delete
                    End If
                Next styT
        End If
End Sub

But I have apparently stumbled upon a workbook that has protected cell styles. As you can see above I have attempted to unprotect the style before deletion but I still have styles I cannot delete.

I tried manually MODIFYing the cell style and unprotecting, then manually deleting and it still doesnt work.

Can any of you help?
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
You can't lock a cell style - you can only include the Locked setting in the style definition which is not the same thing at all. Are there protected sheets in the workbook?
 
Upvote 0
Unfortunately I don't understand your first sentence.

There are no protected sheets in the workbook.
 
Upvote 0
If you look at the dialog for modifying styles, you'll see a bunch of checkboxes as to what formatting options should be included in the Style:
Number
Alignment
Font
Border
Fill
Protection

These all relate to the cell format options. The IncludeProtection property of the style only indicates whether the cell protection settings (Locked and Hidden, as shown on the Protection tab of the Format cells dialog) are included in the style. It does not indicate the style itself is protected in any way.
 
Upvote 0
Ahh, I understand.

So do you have any idea what else could be causing this issue?
I have used this bit of code a hundred times and never experienced this.
 
Upvote 0
mikeTRON, any luck on solving this issue? I'm having the exact same problem

Ahh, I understand.

So do you have any idea what else could be causing this issue?
I have used this bit of code a hundred times and never experienced this.
 
Upvote 0
Nope, and it is BEYOND annoying.

I would get workbooks handed to be with something like 65,000 cell styles!!! WHYYYYYYY?! I would run the macro and it would purge all but about 8 of the nonsensical ones that are NOT defaults.
I have NO idea how to clear them...
 
Upvote 0

Forum statistics

Threads
1,216,552
Messages
6,131,320
Members
449,644
Latest member
tbhoola

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top