When you only want a couple styles from a workbook but not all of them it's easier to merge styles then remove those you don't want.
How can I improve the form or the backing code?
Userform with styles listed.
'CustomStyleRemoverForm
Private Sub UserForm_Initialize()
ListStyles
End Sub
Private Sub ListStyles()
CustomStylesListBox.Clear
Dim listStyle As Style
For Each listStyle In ActiveWorkbook.Styles
If Not listStyle.BuiltIn Then
CustomStylesListBox.AddItem listStyle.Name
End If
Next
End Sub
Private Sub SelectAllButton_Click()
CheckAllBoxes True
End Sub
Private Sub UnselectAllButton_Click()
CheckAllBoxes False
End Sub
Private Sub InvertSelectionButton_Click()
Dim counter As Long
For counter = 0 To CustomStylesListBox.ListCount - 1
CustomStylesListBox.Selected(counter) = Not CustomStylesListBox.Selected(counter)
Next
End Sub
Private Sub CheckAllBoxes(ByVal updateValue As Boolean)
Dim counter As Long
For counter = 0 To CustomStylesListBox.ListCount - 1
CustomStylesListBox.Selected(counter) = updateValue
Next
End Sub
Private Sub RemoveSelectedButton_Click()
Dim counter As Long
For counter = 0 To CustomStylesListBox.ListCount - 1
If CustomStylesListBox.Selected(counter) Then
ActiveWorkbook.Styles(CustomStylesListBox.List(counter)).Delete
End If
Next
ListStyles
End Sub