我当前遇到一个问题,其中我的Outlook VBA代码未更新我的Outlook视图中电子邮件的跟进标志。有趣的是,当我检查作业时,它似乎正在正确更新。下面是我的代码供参考:
Sub RemoveDuplicateItems()
Dim objFolder As Folder
Dim objDictionary As Object
Dim i As Long
Dim objItem As Object
Dim strKey As String
Set objDictionary = CreateObject("scripting.dictionary")
'Select a source folder
Set objFolder = Outlook.Application.Session.PickFolder
If Not (objFolder Is Nothing) Then
For i = objFolder.Items.Count To 1 Step -1
Set objItem = objFolder.Items.Item(i)
Select Case objFolder.DefaultItemType
'Check email subject, body and sent time
Case olMailItem
strKey = objItem.Subject
'MsgBox "Looking at: " + strKey + ", Flag is: " + objItem.FlagRequest
strKey = Replace(strKey, "RE: ", "")
strKey = Replace(strKey, "Re: ", "")
strKey = Replace(strKey, "FW: ", "")
End Select
'Remove the duplicate items
If objDictionary.Exists(strKey) = True Then
If objDictionary(strKey).SentOn <= objItem.SentOn Then
flagString = objDictionary(strKey).FlagRequest
objDictionary(strKey).Delete
objDictionary.Remove strKey
If flagString <> "Follow Up" And flagString <> "" Then
objItem.FlagRequest = flagString
End If
'MsgBox "Stored flag: " + objItem.FlagRequest
objDictionary.Add strKey, objItem
Else
If objItem.FlagRequest <> "Follow Up" And objItem.FlagRequest <> "" Then
objDictionary(strKey).FlagRequest = objItem.FlagRequest
End If
objItem.Delete
End If
Else
objDictionary.Add strKey, objItem
End If
Next i
End If
Set objMsg = Nothing
Set objItem = Nothing
Set objDictionary = Nothing
Set objFolder = Nothing
End Sub
我知道了,我需要保存邮件对象:
objItem.FlagRequest = flagStringobjItem.Save