Est-il possible de supprimer TOUS les styles de cellule personnalisés/créés dans un classeur? Je laisse juste les styles par défaut.
Sans avoir à les supprimer tous un par un
Essayez cette petite macro VBA:
Sub StyleKiller()
Dim N As Long, i As Long
With ActiveWorkbook
N = .Styles.Count
For i = N To 1 Step -1
If Not .Styles(i).BuiltIn Then .Styles(i).Delete
Next i
End With
End Sub
Cela résout le intégré vs Problème personnalisé . Notez que nous exécutons la boucle à l'envers pour éviter de corrompre l'index de la boucle.
Ok, ce n'était pas aussi difficile à faire que je le pensais.
Un peu en désordre car je n'utilise pas souvent vba; mais ce code reviendra aux styles par défaut:
Sub DefaultStyles()
Dim MyBook As Workbook
Dim tempBook As Workbook
Dim CurStyle As Style
Set MyBook = ActiveWorkbook
On Error Resume Next
For Each CurStyle In MyBook.Styles
Select Case CurStyle.Name
Case "20% - Accent1", "20% - Accent2", _
"20% - Accent3", "20% - Accent4", "20% - Accent5", "20% - Accent6", _
"40% - Accent1", "40% - Accent2", "40% - Accent3", "40% - Accent4", _
"40% - Accent5", "40% - Accent6", "60% - Accent1", "60% - Accent2", _
"60% - Accent3", "60% - Accent4", "60% - Accent5", "60% - Accent6", _
"Accent1", "Accent2", "Accent3", "Accent4", "Accent5", "Accent6", _
"Bad", "Calculation", "Check Cell", "Comma", "Comma [0]", "Currency", _
"Currency [0]", "Explanatory Text", "Good", "Heading 1", "Heading 2", _
"Heading 3", "Heading 4", "Input", "Linked Cell", "Neutral", "Normal", _
"Note", "Output", "Percent", "Title", "Total", "Warning Text"
Case Else
CurStyle.Delete
End Select
Next CurStyle
Set tempBook = Workbooks.Add
Application.DisplayAlerts = False
MyBook.Styles.Merge Workbook:=tempBook
Application.DisplayAlerts = True
tempBook.Close
End Sub
Pour tout supprimer sans utiliser INDEX
, essayez ce qui suit:
Sub StyleKiller()
Dim st As Style
On Error Resume Next
For Each st In ActiveWorkbook.Styles
If Not st.BuiltIn Then
st.Delete
End If
Next
On Error GoTo 0
End Sub