ExcelTip.Net留存知识帖 ---【注:附件之前被网盘供应商清空后,现已修复-现已修复-现已修复为本地下载!】
现在位置:首页 > E问E答 > Excel VBA > 如何用VBA获取所有已安装字体的列表?

如何用VBA获取所有已安装字体的列表?

作者:绿色风 分类: 时间:2022-08-17 浏览:82
楼主
rongjun
Q:如何用VBA获取所有已安装字体的列表?
A:使用如下代码:

  1. Sub 显示所有字体()
  2.     Dim FontList As CommandBarControl
  3.     Dim TempBar As CommandBar
  4.     Dim i As Long
  5.     Set TempBar = Application.CommandBars.Add
  6.     Set FontList = TempBar.Controls.Add(ID:=1728)
  7.     For i = 0 To FontList.ListCount - 1
  8.         Cells(i + 1, 1) = FontList.List(i + 1)
  9.     Next i
  10.     TempBar.Delete
  11. End Sub



如何用VBA获取所有已安装字体的列表?.rar
2楼
gvntw
Q:如何获得安装的字体列表?
A:使用字体控件,代码如下:
  1. Sub GetFonts()
  2.     Dim TempBar As CommandBar
  3.     Dim MyFonts As CommandBarControl
  4.     Dim i As Long
  5.     Dim FontCounts As Long
  6.     Dim arr
  7.    
  8.     Set TempBar = Application.CommandBars.Add   '增加一个临时工具栏
  9.     Set MyFonts = TempBar.Controls.Add(ID:=1728)  '工具栏添加字体控件
  10.    
  11.     [a:a] = Empty   '清空A列内容
  12.     FontCounts = MyFonts.ListCount  '取得字体数
  13.     ReDim arr(1 To FontCounts, 0)   '重新定义数组大小
  14.     For i = 1 To FontCounts     '循环字体
  15.         arr(i, 0) = MyFonts.List(i) '把字体赋值给数组
  16.     Next
  17.     Range("A1:A" & FontCounts) = arr    '把数组填到单元格中
  18.    
  19.     Erase arr   '清除数组
  20.     TempBar.Delete  '删除临时工具栏
  21. End Sub
3楼
水星钓鱼
直接用现有的,不需要再增加一个。
  1. Sub xyf()
  2.     Dim obj As CommandBarComboBox
  3.     Dim i As Integer
  4.     Dim arr
  5.     Range("a1") = "字体名称"
  6.     '查找菜单的字体组合框控件
  7.     Set obj = Application.CommandBars.FindControl(ID:=1728)
  8.     For i = 1 To obj.ListCount
  9.         Cells(i + 1, 1) = obj.List(i)
  10.     Next
  11. End Sub
4楼
nmghyh
学习了  谢谢

免责声明

有感于原ExcelTip.Net留存知识的价值及部分知识具有的时间限定性因素, 经与ExcelTip.Net站长Apolloh商议并征得其同意, 现将原属ExcelTip.Net的知识帖采集资料于本站点进行展示, 供有需要的人士查询使用,也慰缅曾经的论坛时代。 所示各个帖子的原作者如对版权有异议, 可与本人沟通提出,或于本站点留言,我们会尽快处理。 在此,感谢ExcelTip.Net站长Apolloh的支持,感谢本站点所有人**绿色风(QQ:79664738)**的支持与奉献,特此鸣谢!
------本人网名**KevinChengCW(QQ:1210618015)**原ExcelTip.Net总版主之一

评论列表
sitemap