Exibir todas as fontes instaladas (Excel) usando VBA no Microsoft Excel

Anonim

A macro abaixo exibirá uma lista de todas as fontes instaladas. Observação! Se você tiver muitas fontes instaladas,
a macro pode parar de responder devido à falta de memória disponível. Se isso acontecer, você pode tentar o
exemplo para o Word posteriormente neste documento.

Sub ShowInstalledFonts () Const StartRow As Integer = 4 Dim FontNamesCtrl As CommandBarControl, FontCmdBar As CommandBar, tFormula As String Dim fontName As String, i As Long, fontCount As Long, fontSize As Integer fontSize = 0 fontSize = Application.InputBox ("Insira a amostra Font Size Between 8 And 30 ", _" Select Sample Font Size ", 12,,,,, 1) If fontSize = 0 Then Exit Sub If fontSize 30 Then fontSize = 30 Defina FontNamesCtrl = Application.CommandBars (" Formatting "). FindControl (ID: = 1728) 'Se o controle de fonte estiver faltando, crie um CommandBar temporário Se FontNamesCtrl não for nada, então defina FontCmdBar = Application.CommandBars.Add ("TempFontNamesCtrl", _ msoBarFloating, False, True) Defina FontNamesCtrl = FontCmdBar.Controls. Adicionar (ID: = 1728) End If Application.ScreenUpdating = False fontCount = FontNamesCtrl.ListCount Workbooks.Add 'lista os nomes das fontes na coluna A e exemplo de fontes na coluna B Para i = 0 Para FontNamesCtrl.ListCount - 1 fontName = FontNamesCtrl.List (i + 1) Application.StatusBar = "Listando fonte" & _ Format (i / (fontCount - 1), "0%") & "" & _ fontName & "…" Células (i + StartRow, 1) .Formula = fontName With Cells (i + StartRow, 2) tFormula = " abcdefghijklmnopqrstuvwxyz "If Application.International (xlCountrySetting) = 47 Then tFormula = tFormula &" æøå "End If tFormula = tFormula & UCase (tFormula) tFormula = tFormula &" NextFormula = Nome da fonte i 1234567890 ".Formula = 1234567890". Application.StatusBar = False If Not FontCmdBar Is Nothing Then FontCmdBar.Delete Set FontCmdBar = Nothing Set FontNamesCtrl = Nothing 'adicionar cabeçalho Colunas (1) .AutoFit With Range ("A1") .Formula = "Fontes instaladas:" .Font.Bold = True .Font.Size = 14 End With With Range ("A3") .Formula = "Nome da fonte:" .Font.Bold = True .Font.Size = 12 End With With Range ("B3") .Formula = " Exemplo de fonte: ".Font.Bold = True .Font.Size = 12 End With With Range (" B "& StartRow &": B "& _ StartRow + fontCount) .Font.Size = fontSize End With With Range (" A "& StartRow &": B "& _ StartRow + fontCount) .VerticalAlignment = xlVAl ignCenter End With Range ("A4"). Selecione ActiveWindow.FreezePanes = True Range ("A2"). Selecione ActiveWorkbook.Saved = True End Sub