AW: nicht installierte Schrift abfangen
16.10.2016 19:57:29
KlausF
Hallo Jens,
wenn Du auf ein spezifisches Aussehen fixiert bist sollte man schon die Standardschriften verwenden.
Unter dem Mac z.B. ist die Standardschrift die Lucida. Wenn ich Wert auf Kompatibilität lege dann
ändere ich das sofort auf Arial oder Verdana. Anderenfalls belegt Excel diese Zellen beim Öffnen einfach
mit der derzeit eingestellten Standardschrift. Das kann unangenehme optische Verschiebungen nach sich
ziehen (Zeilenumbrüche!). Man könnte sich vorher alle installierten Schriften zeigen lassen:
Sub SchriftenAuslesen()
Dim cnt As CommandBarControl
Dim intCounter As Integer
Application.ScreenUpdating = False
Set cnt = Application.CommandBars.FindControl(ID:=1728)
For intCounter = 1 To cnt.ListCount
With Cells(intCounter, 1)
.Value = cnt.List(intCounter)
'.Font.Name = cnt.List(intCounter)
End With
Next intCounter
Columns(1).AutoFit
Application.ScreenUpdating = True
End Sub
oder z.B. nach einem spezifischem Font fragen:
Private Function FontIsInstalled(sFont) As Boolean
FontIsInstalled = False
Set FontList = Application.CommandBars("Formatting").FindControl(Id:=1728)
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
On Error Resume Next
TempBar.Delete
End Function
Private Sub Workbook_Open()
FontName = "Wingdings 2"
If Not FontName = True Then
MsgBox "Zur korrekten Darstellung müssen Sie die Schriftart " _
& FontName & " installieren !", vbExclamation, "Hinweis"
End If
End Sub
Ersetzen ginge in etwa so:
Sub SchriftartenErsetzen()
Dim rng As Range
Dim wks As Worksheet
For Each wks In ThisWorkbook.Worksheets
For Each rng In wks.UsedRange
'If rng.Font.Name = "Verdana" Then
If rng.Font.Name "Arial" Then
rng.Font.Name = "Arial"
End If
Next
Next
End Sub
Gruß
Klaus