VBA——获取字体列表

来源:互联网 发布:制作价格表的软件 编辑:程序博客网 时间:2024/06/05 08:00

自己动手做了一个可以改变所有ppt的字体格式的小插件,使用VBA开发。开发过程中,因为不想自己将字体的类型一个个add进combox(这样子多累啊),就写了下面这个自动获取字体类型的函数,并将其写入到combox中。

Sub getFont()    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       fontName.AddItem (FontList.List(I + 1))    Next I    On Error Resume Next    TempBar.DeleteEnd Sub

其中,fontName是combox控件,运行结果如下。


0 0