admin管理员组文章数量:1406354
I'm trying to remove a flag from an Outlook message, and my code works sometimes but not always. How can I remove a flag from any message?
Here's the code that sometimes does not work:
If Not myMailItem.FlagStatus <> olNoFlag Or myMailItem.FlagRequest <> vbNullString Then
myMailItem.FlagStatus = olNoFlag
myMailItem.FlagRequest = vbNullString
End If
I posted an answer but I'm open to better solutions and improvements.
I'm trying to remove a flag from an Outlook message, and my code works sometimes but not always. How can I remove a flag from any message?
Here's the code that sometimes does not work:
If Not myMailItem.FlagStatus <> olNoFlag Or myMailItem.FlagRequest <> vbNullString Then
myMailItem.FlagStatus = olNoFlag
myMailItem.FlagRequest = vbNullString
End If
I posted an answer but I'm open to better solutions and improvements.
Share Improve this question edited Mar 6 at 18:41 ChrisB asked Mar 6 at 2:09 ChrisBChrisB 3,2415 gold badges40 silver badges68 bronze badges2 Answers
Reset to default 1I had to look at the MailItem.TaskDueDate
and MailItem.ReminderTime
properties. I suspect that when an Outlook rule flagged a message, the rule set these properties but did not set the MailItem.ReminderSet
or MailItem.FlagRequest
properties.
Here's what finally worked for me:
If myMailItem.TaskDueDate <> #1/1/4501# Or myMailItem.ReminderTime <> #1/1/4501# Or myMailItem.ToDoTaskOrdinal <> #1/1/4501# Or myMailItem.IsMarkedAsTask Or myMailItem.ReminderSet Or myMailItem.FlagStatus <> OlFlagStatus.olNoFlag Or myMailItem.FlagRequest <> vbNullString Then
myMailItem.TaskDueDate = #1/1/4501# ' null date is #1/1/4501#
myMailItem.ReminderTime = #1/1/4501# ' null date is #1/1/4501#
myMailItem.ToDoTaskOrdinal = #1/1/4501# ' null date is #1/1/4501#
targetMailItem.ClearTaskFlag ' use this method since IsMarkedAsTask property can't be changed directly
myMailItem.ReminderSet = False
myMailItem.FlagRequest = vbNullString
End If
Your issue comes from the incorrect logic in your If condition and using an incorrect variable (iMailItem instead of myMailItem).
If the flag is not being removed reliably, try the following approach:
Updated Code:
Dim myMailItem As Outlook.MailItem
' Ensure the mail item is valid before proceeding
If Not myMailItem Is Nothing Then
' Remove the flag properly
myMailItem.ClearTaskFlag
' Save changes
myMailItem.Save
End If
本文标签: vbaHow Do I Remove a Flag from an Email in OutlookStack Overflow
版权声明:本文标题:vba - How Do I Remove a Flag from an Email in Outlook - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744999242a2636871.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论