【问题标题】:Populate combobox in VBA via any api or something else通过任何 api 或其他方式在 VBA 中填充组合框
【发布时间】:2015-08-15 02:42:48
【问题描述】:
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

这不起作用。我想在用户窗体上填充一个组合框并避免硬编码条目。

【问题讨论】:

  • 您是在问如何将项目添加到组合框?,还是您真的在问如何在运行时枚举已安装的字体?。它们几乎不是一回事。
  • 是的,你说得对,我的问题是..如何在运行时枚举已安装的字体?在我的代码中.. 因为想在组合框中的 vba 代码中使用安装字体

标签: vba


【解决方案1】:

使用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

【讨论】:

  • 感谢债券编辑我的问题,但我想知道任何 Windows API 来填充我的组合框。带有所有字体名称..
  • @NeerajSinghChouhan:您不需要 Windows API 来将项目添加到组合框;正如 Bond 所指出的,您使用它的 AddItem 方法。我想你问错问题了。请参阅我对上述问题的评论。
猜你喜欢
  • 1970-01-01
  • 2015-01-03
  • 2014-12-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多