View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
[email protected] dave.cuthill@computalog.com is offline
external usenet poster
 
Posts: 53
Default Checking if a font is installed (2007)

I have been using the attached function to determine if a specific
font is installed. It seems to work fine is I have my macro security
set at "Enable all Macros" but when I set the macro security to
"Disable all macros with notification" I get an error at For i=0 to
Fontlist.listcount - 1 when I am prompted and allow macros to run.


Runtime error '-2147467259 (80004005): Method 'ListCount of object
_commandbarcombox failed ...

This always ran fine in 2003.

Function FontIsInstalled(sFont) As Boolean
' Returns True if sFont is installed
FontIsInstalled = False
Set FontList =
Application.CommandBars("Formatting").FindControl( ID:=1728)

' If Font control is missing, create a temp CommandBar
If FontList Is Nothing Then
Set TempBar = Application.CommandBars.Add
Set FontList = TempBar.Controls.Add(ID:=1728)
End If

For i = 0 To FontList.ListCount - 1
If FontList.List(i + 1) = sFont Then
FontIsInstalled = True
On Error Resume Next
TempBar.Delete
Exit Function
End If
Next i

' Delete temp CommandBar if it exists
On Error Resume Next
TempBar.Delete
End Function