Thread: [Solved] Capture a Font in a Variable
View Single Post
 
Old 05-30-2012, 07:25 PM
joatmon joatmon is offline Windows 7 64bit Office 2010 64bit
Novice
 
Join Date: May 2012
Posts: 14
joatmon is on a distinguished road
Default Capture a Font in a Variable

On a userform, I have various labels that I need to set the font on at form initialization based on the version of Excel that the user has (since different fonts are available on different versions of Excel). Here is what I have but it is crashing on me:

Code:
Private Sub UserForm_Initialize()
    
    Dim myFont As Font
    
    'Set fonts on controls based on version of Excel
    If Application.Version > 12 Then 'this is for Excel 2010
        myFont = "Chiller"
    Else: myFont = "Arial" 'older versions of Excel
    End If

    'Set the various controls
    Me.Label1.Font = myFont
    Me.Label2.Font = myFont
    Me.Label3.Font = myFont
    'etc
It crashes on the myFont = "Chiller" line. I tried this with and without the string quotes. I also used a msgbox to show me that the word "Chiller" is the correct font.

Can anybody tell me how to capture the name of a font in a variable so that I can use this variable to set the fonts on my different labels (and other controls)?

Thanks.
Reply With Quote