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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 16:25:46  来源:igfitidea点击:

Change individual listbox item font in Excel

excelvbaexcel-vbaexcel-2007

提问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

使用复选框选项使您的列表框成为多选列表框。查看快照

enter image description here

在此处输入图片说明

To get this type of listbox you can either set the properties in design time or at run time. For example

要获得这种类型的列表框,您可以在设计时或运行时设置属性。例如

DESIGN TIME

设计时间

enter image description here

在此处输入图片说明

RUN TIME

运行

Private Sub UserForm_Initialize()
    With ListBox1
        .MultiSelect = fmMultiSelectMulti
        .ListStyle = fmListStyleOption
    End With
End Sub