|
自己用的一段vba代码,功能是根据发件人分类邮件。就是在inbox下建立以发件人命名的目录,然后把邮件移到该目录下。
比较简单,有不足的地方,望不吝指出,共同进步。
如果你有什么类似的需求,可以提出。
Sub 按发件人分类邮件()
On Error Resume Next
Dim myOlApp, myNamespace,As Object
Dim obInbox As Object
Set myOlApp = CreateObject("outlook.application")
Set myNamespace = myOlApp.GetNamespace("MAPI")
Set obInbox = myNamespace.GetDefaultFolder(olFolderInbox)
Dim foldercount As Integer
foldercount = obInbox.Folders.Count
'For i = 1 To foldercount
'Set t = obInbox.Folders.item(1)
't.Delete
'Next
'Exit Sub
foldercount = obInbox.Items.Count
Dim item As Object
Dim temp As Object
For i = 1 To foldercount
Set item = obInbox.Items(1)
Set myCopiedItem = item.Copy
Set temp = Nothing
Set temp = obInbox.Folders.item(item.SenderName)
If temp Is Nothing Then
Set temp = obInbox.Folders.Add(item.SenderName)
End If
myCopiedItem.Move temp
item.Delete
Next
End Sub |
|