vba 在 Excel 中更改单个列表框项目字体
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10944064/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Change individual listbox item font in Excel
提问by BiGXERO
I want to change the property of just a single item in a list box. I currently have the user select an item from the list box, which is then passed as a parameter for processing. I want to be able to either remove the item form the list, or, even better, change the font so they can see which items have to be processed, and which have already been completed.
我只想更改列表框中单个项目的属性。我目前让用户从列表框中选择一个项目,然后将其作为参数传递以进行处理。我希望能够从列表中删除项目,或者更好的是更改字体,以便他们可以看到哪些项目必须处理,哪些已经完成。
I have the following code:
我有以下代码:
Sub updateLaunchScreen_CrossDayOff()
Dim i As Long
With ReadingsLauncher
With .dayListBox
For i = 0 To .ListCount - 1
If .Selected(i) Then
.Font.Strikethrough = True
End If
Next i
End With
End With
End Sub
However this changes every item in the list.
但是,这会更改列表中的每个项目。
I have googled the issue but havent been able to find anything specifically relating to changing the property of a single list item in a list box.
我在 google 上搜索了这个问题,但没有找到任何与更改列表框中单个列表项的属性有关的内容。
Any help would be greatly appreciated.
任何帮助将不胜感激。
回答by Siddharth Rout
I want to be able to either remove the item form the list
我希望能够从列表中删除项目
If you want to delete the item then I would suggest this
如果您想删除该项目,那么我建议您这样做
Option Explicit
Private Sub CommandButton1_Click()
If ListBox1.ListIndex > -1 Then
ListBox1.RemoveItem (ListBox1.ListIndex)
End If
End Sub
or, even better, change the font so they can see which items have to be processed, and which have already been completed.
或者,更好的是更改字体,以便他们可以看到哪些项目必须处理,哪些已经完成。
If you want to see which items have been processed then you can use this option.
如果您想查看已处理的项目,则可以使用此选项。
Make your Listbox a MultiSelect listbox with Checkbox options. See Snapshot
使用复选框选项使您的列表框成为多选列表框。查看快照
To get this type of listbox you can either set the properties in design time or at run time. For example
要获得这种类型的列表框,您可以在设计时或运行时设置属性。例如
DESIGN TIME
设计时间
RUN TIME
运行
Private Sub UserForm_Initialize()
With ListBox1
.MultiSelect = fmMultiSelectMulti
.ListStyle = fmListStyleOption
End With
End Sub