Okay,
I have Listbox1 that loads my installed fonts. I have ComboBox1 that I send my "Favorite Fonts" to for future access.
Issue:
When I add Fonts (from Listbox) to My Favorite Fonts (ComboBox) and the form closes; The fonts I've added to my ComboBox disappears. I tried Save Settings and Get settings but I'm doing something Wrong. So Instead of displaying my mistakes. Ill show you what I have now and you can help me along from here?
Private Sub CommandButton1_Click()
Dim i As Long
i = Listbox1.ListIndexComboBox1.AddItem Listbox1.List(i, 0), 0
End Sub
'===========================================
Private Sub LoadInstalledFonts()
Dim myFonts As Integer, i As Integer, v As Variant Dim startFont As String startFont = "Arial" myFonts = 0 i = 0 For Each v In FontListListbox1.AddItem v If v = startFont Then myFonts = i i = i + 1 Next v Listbox1.ListIndex = myFontsEnd Sub
Private Sub UserForm_Initialize()LoadInstalledFonts
So, After I add my favorite fonts to my combobox... How do I keep them there?
Your CommandButton1_Click() Sub will become:
1 2 3 4 5 6 7 8 9 10 11 12 13
Private Sub CommandButton1_Click() Dim i As Long, lstFonts As String i = ListBox1.ListIndex ComboBox1.AddItem ListBox1.list(i) ComboBox1.ListIndex = ComboBox1.ListCount - 1 For i = 0 To ComboBox1.ListCount - 1 lstFonts = lstFonts & ComboBox1.list(i) & "|" Next i lstFonts = Left(lstFonts, Len(lstFonts) - 1) SaveSetting "FavoriteFonts", "Settings", "FavoriteList", lstFonts End Sub
You will create the Sub able to load from Registry:
1 2 3 4 5 6 7 8
Private Sub LoadFavorites() Dim lstFonts As String, arrayFonts As Variant, f As Variant lstFonts = GetSetting("FavoriteFonts", "Settings", "FavoriteList", "No fonts...") arrayFonts = Split(lstFonts, "|") For Each f In arrayFonts Me.ComboBox1.AddItem f Next End Sub
And you will call it on the Form Initialize event:
1 2 3 4
Private Sub UserForm_Initialize() LoadInstalledFonts LoadFavorites End Sub
I used a one column listbox and one column combobox. I would also avoid the button using. Instead of it I would use the listbox doubleclick event...
Is that what you need?