在Excel中更改单个列表框项目字体 [英] Change individual listbox item font in Excel

查看:234
本文介绍了在Excel中更改单个列表框项目字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想更改列表框中单个项目的属性。我目前有用户从列表框中选择一个项目,然后将其作为参数传递进行处理。我想要能够从列表中删除项目,或者更好的是更改字体,以便他们可以看到哪些项目必须被处理,哪些项目已经完成。



我有以下代码:

  Sub updateLaunchScreen_CrossDayOff()

Dim i As Long

With ReadingsLauncher

With .dayListBox
For i = 0 To .ListCount - 1
如果.Selected(i)Then
Font.Strikethrough = True
End If
Next i
End with

End with

End Sub

但是,这会更改列表中的每个项目。



我已经google了这个问题,但是没有找到与更改列表框中单个列表项的属性有关的任何东西。



任何帮助将不胜感激。 >

解决方案


我想要删除列表中的项目


如果要删除该项目然后我会建议这个

  Option Explicit 

Private Sub CommandButton1_Click()
如果ListBox1.ListIndex> -1然后
ListBox1.RemoveItem(ListBox1.ListIndex)
End If
End Sub




或者更好的是更改字体,以便他们可以看到哪些项目必须被处理,哪些项目已经完成。




如果您想查看哪些项目已被处理,那么您可以使用此选项。



将您的列表框设置为MultiSelect列表框与复选框选项。请参阅快照





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



设计时间





运行时间

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


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.

Any help would be greatly appreciated.

解决方案

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

这篇关于在Excel中更改单个列表框项目字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆