一位客户问我这个问题,她的邮箱似乎已满(运行 Exchange SBS2011、Outlook 2010),有 6GB。她不想要求更多空间,而是想删除不需要的电子邮件。
问:有没有办法对电子邮件进行排序,以便查看特定发件人的电子邮件使用了多少空间?
答案1
一种可能的部分自动化方法。
第一:根据发件人创建一个搜索文件夹。可以自动化。http://www.slipstick.com/developer/create-an-outlook-search-folder-using-vba/
Sub SearchFolderForSender()
On Error GoTo Err_SearchFolderForSender
Dim strFilter As String
' lets get the email address from a selected message
Dim oMail As Outlook.MailItem
Set oMail = ActiveExplorer.Selection.Item(1)
strFilter = oMail.SenderEmailAddress
If strFilter = "" Then Exit Sub
Dim strDASLFilter As String
' From email address
Const From1 As String = "http://schemas.microsoft.com/mapi/proptag/0x0065001f"
Const From2 As String = "http://schemas.microsoft.com/mapi/proptag/0x0042001f"
strDASLFilter = "(""" & From1 & """ CI_STARTSWITH '" & strFilter & "' OR """ & From2 & """ CI_STARTSWITH '" & strFilter & "')"
' From Display name
'strDASLFilter = """urn:schemas:httpmail:fromname"" LIKE '" & strFilter & "' "
Dim strScope As String
strScope = "Inbox"
Dim objSearch As Search
Set objSearch = Application.AdvancedSearch(Scope:=strScope, Filter:=strDASLFilter, SearchSubFolders:=True, Tag:="SearchFolder")
'Save the search results to a searchfolder
objSearch.Save (strFilter)
Set objSearch = Nothing
Exit Sub
Err_SearchFolderForSender:
MsgBox "Error # " & Err & " : " & Error(Err)
End Sub
第二步:进入搜索文件夹。
第三:选择全部项目。
可以实现自动化。
Sub ctrlHomeCtrlEnd()
SendKeys ("^{HOME}^+{END}")
End Sub
第四:对 Size 属性求和。 http://www.vbaexpress.com/forum/showthread.php?47283-Custom-Field-loop-through-each-email-and-add-the-value
Sub SizeCount()
' http://www.vbaexpress.com/forum/showthread.php?47283-Custom-Field-loop-through-each-email-and-add-the-value
Dim myOlExp As Explorer
Dim myOlSel As Selection
Dim oItem As Object
Dim itemSize As Double
Dim tmpValue As Double
Dim x As Long
Dim uBegin
Dim uDuration
Dim uMsg As String
Set myOlExp = Application.ActiveExplorer
Set myOlSel = myOlExp.Selection
tmpValue = 0
uBegin = Now
'Debug.Print " Start: " & Now
For x = 1 To myOlSel.count
Set oItem = myOlSel.item(x)
itemSize = oItem.ItemProperties.item("Size")
If oItem.ItemProperties.item("Size") = "" Then
itemSize = 0
End If
'Debug.Print "x: " & x & " - " & itemSize; ""
tmpValue = tmpValue + itemSize
Next x
uDuration = dateDiff("s", uBegin, Now)
Debug.Print " End : " & Now & " Total time: " & uDuration & " seconds."
uMsg = " Total Size of " & myOlSel.count & " items: " & Format$(tmpValue / 1000, "0.00") & " KB"
Debug.Print uMsg & vbCr
MsgBox uMsg
子目录结束
利用按钮上的三个宏,这个繁琐的过程也许会变得可行。