Set FontList = Application.CommandBars("Formatting").FindControl(ID:=1728)
' If Font control is missing, create a temp CommandBar
If FontList Is Nothing Then
Set Tempbar = Application.CommandBars.Add
Set FontList = Tempbar.Controls.Add(ID:=1728)
End If
' Put the fonts into column A
'Range("A:A").ClearContents
For i = 0 To FontList.ListCount - 1
cbmFontList.value = FontList.List(i + 1)
Next i
' Delete temp CommandBar if it exists
On Error Resume Next
Tempbar.Delete
这不起作用。我想在用户表单上填充组合框并避免使用硬编码条目。
答案 0 :(得分:0)
使用AddItem()
功能将项目添加到组合框中。假设您的表单对象名为UserForm1
:
' Clear any entries...
UserForm1.cmbFontList.Clear
' Add each font...
For i = 1 To FontList.ListCount
UserForm1.cbmFontList.AddItem FontList.List(i)
Next i
' Show the form...
UserForm1.Show