So I run this code to delete cell styles normally.
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?
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?