vba - 根据正文中的字符数删除重复任务
问题描述
我目前正在运行一个宏,该宏在启动时运行规则以创建任务,然后删除重复的任务。但是,因为我正在对新任务进行编辑,宏无法识别有两个同名任务,因为正文不同。有没有办法修改宏来查找正文中的字符数?例如
If .body>"32" Then
?????
End If
这是我目前拥有的代码。原始代码来自 https://www.datanumen.com/blogs/quickly-remove-duplicate-outlook-items-folder-via-vba/ & https://www.slipstick.com/outlook/rules/run-outlook-规则启动/
Private Sub Application_Startup()
RunAllInboxRules
RemoveDuplicateItems
End Sub
Sub RunAllInboxRules()
Dim st As Outlook.Store
Dim myRules As Outlook.Rules
Dim rl As Outlook.Rule
Dim count As Integer
Dim ruleList As String
'On Error Resume Next
' get default store (where rules live)
Set st = Application.Session.DefaultStore
' get rules
Set myRules = st.GetRules
' iterate all the rules
For Each rl In myRules
' determine if it's an Inbox rule
If rl.RuleType = olRuleReceive And rl.IsLocalRule = True Then
' if so, run it
rl.Execute ShowProgress:=True
count = count + 1
ruleList = ruleList & vbCrLf & rl.Name
End If
Next
' tell the user what you did
ruleList = "These rules were executed against the Inbox: " & vbCrLf & ruleList
MsgBox ruleList, vbInformation, "Macro: RunAllInboxRules"
Set rl = Nothing
Set st = Nothing
Set myRules = Nothing
End Sub
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 & "," & objItem.Body & "," & objItem.SentOn
'Check appointment subject, start time, duration, location and body
Case olAppointmentItem
strKey = objItem.subject & "," & objItem.Start & "," & objItem.Duration & "," & objItem.Location & "," & objItem.Body
'Check contact full name and email address
Case olContactItem
strKey = objItem.FullName & "," & objItem.Email1Address & "," & objItem.Email2Address & "," & objItem.Email3Address
'Check task subject, start date, due date and body
Case olTaskItem
strKey = objItem.subject & "," & objItem.StartDate & "," & objItem.DueDate & "," & objItem.Body
End Select
strKey = Replace(strKey, ", ", Chr(32))
'Remove the duplicate items
If objDictionary.Exists(strKey) = True Then
objItem.Delete
Else
objDictionary.Add strKey, True
End If
Next i
End If
End Sub
解决方案
以下是如何.Body
使用数字而不是字符串来检查 - 的长度。
If Len(.Body) > 32 Then
推荐阅读
- mysql - 用零存储日期(无效的日期时间格式)
- python-3.x - 自定义 def __str__(self): 在 Python 中创建类时的方法
- linux - 在 Tails 上运行 Electron AppImage 时如何静音警告?
- reactjs - 当内容高度动态变化时,PerfectScrollBar 将项目保持在视图中
- c++ - 如何使用像素着色器从 Wavefront Obj 文件中渲染材质?
- php - 如何将 PHP 中的变量从网页脚本共享到从命令行永久运行的脚本
- mysql - 查询后找不到mysql记录时如何修复UnhandledPromiseRejectionWarning
- vectorization - 制作训练模型的进度条
- python - 如何修复在 Windows 10 上安装 psutil 的错误?
- charts - Laravel 8 ConsoleTvs / Charts 7 实现 Chartjs 选项