PDA

View Full Version : Solved: Check for Font Availability?



clhare
02-23-2007, 08:37 AM
In a Word template, is there a way to check to see if a user has a specific font available. If they do, continue running the template, but if not, cancel with message?

fumei
02-23-2007, 10:44 AM
Yes. Put the following in the Document_New event of the template.Private Sub Document_New()
Dim aFont
Dim sFontToCheck As String
Dim bolFound As Boolean
sFontToCheck = InputBox("Name of font to check.")
For Each aFont In FontNames
If aFont = sFontToCheck Then
bolFound = True
If bolFound = True Then
Exit For
End If
End If
Next
If bolFound = True Then
MsgBox "Font is available."
Else
MsgBox "Font is not listed. Template will close."
ActiveDocument.Close wdDoNotSaveChanges
End If
End SubYou use this for testing. When you clone the template to a new document, you get the Inputbox displayed.

Test with Arial. It is (most likely) available, so the template finishes.

Test with dflhslfsurnba. It is NOT listed, so the new document is closed without saving.

If you have a specific font in mind, then use that instead of an input box - which is only there for demo purposes anyway.Dim aFont
Dim sFontToCheck As String
Dim bolFound As Boolean

sFontToCheck = "Times New Roman"
For Each aFont In FontNames
If aFont = sFontToCheck Then
' yadda yadda yadda

fumei
02-23-2007, 10:52 AM
NOTE!!!!

FontNames is case sensitive.

"Times new Roman" would fail. It is "Times New Roman".

You could of course error trap that.
If Ucase(aFont) = UCase(sFontToCheck) ThenBoth are made uppercase for the check. However, "Times NewRoman" would fail - no space. Which of course could ALSO be error trapped.

I am assuming that you have a specific font in mind, and will take care to hard code it in correctly.....