Get a list of all fonts in VBA Excel 2010

后端 未结 2 592
情深已故
情深已故 2021-01-23 18:40

I am working in excel VBA and I want to get the list of all fonts in a combo box

Can any one help me please

I tried this code but i am getting error in listcount

2条回答
  •  醉梦人生
    2021-01-23 19:28

    The FontList should be returning a list that is indexed as 1 based. There is no need to start at 0.

    Dim FontList
    Dim i As Long
    
    Set FontList = Application.CommandBars("Formatting").FindControl(ID:=1728)
    
    'Put the fonts into column A
    For i = 1 To FontList.ListCount
        Debug.Print FontList.List(i)
        Cells(Rows.Count, 1).End(xlUp)(2) = FontList.List(i)
        'combobox.AddItems FontList.List(i)
        If i > 50 Then Exit For
    Next i
    

    That should build a list of fonts into column A of the ActiveSheet. When that is working, remove the commenting so that it goes into your combobox.

    Note that you will be getting a list of fonts that exactly duplicates the font list dropdown on the Home ribbon. There will likely ba a few duplicates as that list duplicates a couple of fonts at the top of the list for the default Heading and Body categories.

提交回复
热议问题