VBA – Is a Font Installed

I recently had an issue believed to be linked to the fact that the font I was using (a very common font) might not be installed on a specific server. I thought it would be very easy to validate this by adding a simple function in VBA, but as it turns out, this seems to be quite a challenge.

Below was my solution. Since I know that the computers in question all had MS Office installed, and thus Word will be present, I utilized Word automation.

'---------------------------------------------------------------------------------------
' Procedure : IsFontInstalled
' Author    : Daniel Pineault, CARDA Consultants Inc.
' Website   : http://www.cardaconsultants.com
' Purpose   : Verify is the specified font is installed or not
' Copyright : The following may be altered and reused as you wish so long as the
'             copyright notice is left unchanged (including Author, Website and
'             Copyright).  It may not be sold/resold or reposted on other sites (links
'             back to this site are allowed).
'
' Input Variables:
' ~~~~~~~~~~~~~~~~
' sFontName : Name of the Font to search for
'
' Usage:
' ~~~~~~
' IsFontInstalled("Arial")
'
' Revision History:
' Rev       Date(yyyy/mm/dd)        Description
' **************************************************************************************
' 1         2015-10-15              Initial Release
'---------------------------------------------------------------------------------------
Public Function IsFontInstalled(sFontName As String) As Boolean
    On Error GoTo Error_Handler
    Dim oWord                 As Object
    Dim i                     As Long

    Set oWord = CreateObject("Word.Application")
    For i = 1 To oWord.FontNames.Count
        If LCase(oWord.FontNames(i)) = LCase(sFontName) Then
            IsFontInstalled = True
            Exit For
        End If
    Next I

Error_Handler_Exit:
    On Error Resume Next
    oWord.Quit
    Set oWord = Nothing
    Exit Function

Error_Handler:
    MsgBox "The following error has occurred." & vbCrLf & vbCrLf & _
           "Error Number: " & Err.Number & vbCrLf & _
           "Error Source: IsFontInstalled" & vbCrLf & _
           "Error Description: " & Err.Description, _
           vbCritical, "An Error has Occurred!"
    Resume Error_Handler_Exit
End Function

If you want an alternative approach, one that doesn’t require Word being installed, then be sure to check out: