1
\$\begingroup\$

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.

Userform

'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
\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

There is not much to review, your code is clean. There are some things that you can do to improve User Experience (UX).

  • Replace the label, SelectAllButton and UnselectAllButton with a checkbox.
  • Place a Frame around the Controls
  • Add a ComboBox to change target workbooks
  • Add buttons to copy and paste styles between workbooks

enter image description here

And if you want to go buckwild you could add a Preview Button

enter image description here

\$\endgroup\$
2
  • \$\begingroup\$ For your styles preview did you use a ListBox? I can't figure out how to change the BackColor and ForeColor text for each element. \$\endgroup\$
    – IvenBach
    Commented Jan 30, 2019 at 20:59
  • \$\begingroup\$ @IvenBach I used a WebBrowser control using the CellStyleCSS class from Using Excel Cell StyleElements to Style HTML Document \$\endgroup\$
    – TinMan
    Commented Jan 30, 2019 at 22:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.