问题
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.
回答1:
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
来源:https://stackoverflow.com/questions/10944064/change-individual-listbox-item-font-in-excel