Mark an item with a particular category
I want to mark an item with a particular category, based on the text within the item.
I have the following code.
Sub ProcessRSS()
' Read RSS items and process the usful ones.
Dim objList As Object
Dim objItem As Object
Dim iCount As Integer
Set objList = Applicati开发者_如何学Pythonon.ActiveExplorer.CurrentFolder.Items
iCount = 0
For Each objItem In objList
If (InStr(objItem.Body, "(WA)") > 0) Then
objItem.Categories = "Important"
If (InStr(objItem.Categories, "Important") > 0) Then
iCount = iCount + 1
End If
End If
Next
Debug.Print "Marked " & iCount & " RSS Items as important."
End Sub
I select the folder and then run the macro, but it won't mark the category.
You need to .Save
your item after you update the category. Below is your For loop with the save. As a side note, keep in mind that you'll be overwriting any existing categories as .Categories
is a comma-delimited string. You may want to test if .Categories
is empty and, if not, add ", Important".
For Each objItem In objList
If (InStr(objItem.Body, "(WA)") > 0) Then
objItem.Categories = "Important"
objItem.Save
If (InStr(objItem.Categories, "Important") > 0) Then
iCount = iCount + 1
End If
End If
Next
精彩评论