Add list of Font Names to ComboBox


Posted by JAF on December 27, 2001 8:10 AM

I have a UserForm which contains a ComboBox.

What I'd like to do is to have the CobmoBox populate with a list of the installed fonts on the PC on which the spreadsheet is opened.

I can get the ComboBox to fill with numbers, but not with names see code below.

I'm sure it's a simple matter to get the font names, but I just can't figure it out!!

Any suggestions??

JAF
---------------------------------------------------
Private Sub UserForm_Initialize()
'currently adds numbers - I need font names!!
Me.cboFont.Clear
Set FontList = Application.CommandBars("Formatting").FindControl(ID:=1728)
For i = 0 To FontList.ListCount - 1
Me.cboFont.AddItem i
Next i
End Sub

Posted by JAF on December 27, 2001 8:43 AM

Not having a good day. Realised what the problem is...

Correct code is (if anyone's interested):
Private Sub UserForm_Initialize()
Me.cboFont.Clear
Set FontList = Application.CommandBars("Formatting").FindControl(ID:=1728)
For i = 0 To FontList.ListCount - 1
Me.cboFont.AddItem FontList.List(i + 1)
Next i
End Sub

Boy - do I feel stupid!!!!

Posted by Joe Was on December 27, 2001 8:51 AM

Don't

Don't feel stupid, when working with loops it is easy to mixup a "count" and the "list." JSW

: I have a UserForm which contains a ComboBox. : JAF : --------------------------------------------------- : Private Sub UserForm_Initialize() : 'currently adds numbers - I need font names!! : Me.cboFont.Clear : Set FontList = Application.CommandBars("Formatting").FindControl(ID:=1728) : For i = 0 To FontList.ListCount - 1 : Me.cboFont.AddItem i : Next i : End Sub



Posted by Mike on December 27, 2001 9:14 AM

Try this instead:

Me.cboFont.AddItem fontlist.list(i)

But I noticed 0 doesn't work. Start your loop with 1.

-Mike