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

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.

Forum statistics

Threads
1,216,106
Messages
6,128,863
Members
449,473
Latest member
soumyahalder4

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