Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-30-2012, 07:25 PM
joatmon joatmon is offline Capture a Font in a Variable Windows 7 64bit Capture a Font in a Variable Office 2010 64bit
Novice
Capture a Font in a Variable
 
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
  #2  
Old 05-30-2012, 08:23 PM
joatmon joatmon is offline Capture a Font in a Variable Windows 7 64bit Capture a Font in a Variable Office 2010 64bit
Novice
Capture a Font in a Variable
 
Join Date: May 2012
Posts: 14
joatmon is on a distinguished road
Default

I figured it out. Here is the code for anyone who might stumble on this:

Code:
Private Sub UserForm_Initialize()
    
    Dim myFont As String
    
    '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.Name = myFont
    'etc
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to capture start and ending Ref. Nos. in an array KIM SOLIS Excel 5 09-07-2011 07:43 AM
Variable fields? Emalee77 PowerPoint 0 01-30-2011 05:58 PM
Capture a Font in a Variable Variable Table_Array in VLOOKUP pdab09 Excel 3 11-23-2010 05:28 AM
capture sender's contact to 'Contacts Folder' gianimpact Outlook 0 02-09-2010 07:56 AM
Inputting variable data axy Word 0 09-08-2009 04:50 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:02 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft