Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Drop down list showing user's installed fonts

Status
Not open for further replies.

tedmillerx

Programmer
Jan 6, 2001
52
US
My customers want to be able to change a report's font. I know how to write the code for changing a font based on the results of a combo box, but I don't know how to make a combo box list all the fonts on the user's computer.

I know I could just make a combo box listing the common fonts (Arial, Times, etc). But some customers want a weird font only available on their own computer.

Any ideas on how to list all the user's installed fonts in a combo box? Something that'll work for Vista, XP and 2000?
 
The fonts are stored on your C drive. You could use the Dir() function to iterate through certain file types on the C drive folders that hold fonts and load them into the combo box on the form load.

ProDev, Builders of Affordable Software Applications
Visit me at ==>
May God bless you beyond your imagination!!!
 
Thank you for the quick response. I seem to be a little thick today. I tried with the following code, where cmbFont is the combo box. Didn't work. Am I missing something?

Private Sub Form_Load()
cmbFont = Dir("C:\Windows\Fonts")
End Sub

Sorry. I'm pretty rusty at this.
 
Try this...

Code:
Private Sub Form_Load()

    Dim fontName As String
    
    fontName = Dir("c:\fonts\")
    Me.cmbFont.AddItem (fontName)
    
    Do While fontName <> ""
        fontName = Dir
        Me.cmbFont.AddItem (fontName)
    Loop

End Sub

Your form's combo box must be set to Value List for the Row Source Type.



ProDev, Builders of Affordable Software Applications
Visit me at ==>
May God bless you beyond your imagination!!!
 
Cool! Got it to work. Thank you very much, Lonnie.

I know this might be asking a lot, but is it possible to display the font's actual name instead of the file name? "ARIALN.TTF" looks a lot less pleasant than "Arial".
 
try this

Code:
Function ListFontsToComboBox()
Dim woobj As Word.Application
Set woobj = CreateObject("Word.Application")
With woobj
Dim strFont
For Each strFont In .FontNames
Me.cmbfonts.RowSource = Me.cmbfonts.RowSource & ";" & strFont
Next strFont
End With
woobj.Quit
Set woobj = Nothing
End Function
 
pwise-

I tried calling that function at the end of Lonnie's code. is that what you mean for me to do?

I get the following error: "User defined type not defined" and it highlights the line, "Dim woobj As Word.Application
 
...also, I'm using this in a standalone 2002 runtime environment where some users won't have Word. does that matter?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top