搜索已发送的邮件并将多封邮件移至文件夹 [英] Search sent mail and move multiple mail to a folder

查看:188
本文介绍了搜索已发送的邮件并将多封邮件移至文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在SentMail文件夹中搜索收件人"结尾的邮件,让我们说.cn并将其移至个人文件夹.

I try to search the SentMail folder for mail where To address ends with, lets say .cn and move it to a personal folder.

代码可以工作,但不能移动所有邮件,因为每次运行它都需要多发送一些邮件.

The code work but doesn't move all the mail, for every time I run it it's take a few more mail.

如果我有24个以.cn结尾的邮件,则需要13、6、3、2,因此最终它会找到所有邮件,但不会同时运行.

If I have 24 mails that ends with .cn it takes 13,6,3,2 so in the end it finds all the mail but not on the same run.

有人有什么主意吗?

Sub Search_SentMail()

Dim myOlApp As New Outlook.Application
Dim MyNameSpace As Outlook.NameSpace
Dim MyInbox As Outlook.MAPIFolder
Dim myitems As Outlook.Items
Dim myItem As Object

Set MyNameSpace = myOlApp.GetNamespace("MAPI")
Set MyInbox = MyNameSpace.GetDefaultFolder(olFolderInbox)
Set myOutbox = MyNameSpace.GetDefaultFolder(olFolderSentMail)
Set myitems = myOutbox.Items

Dim junk As Outlook.Folder
Set junk = MyNameSpace.GetDefaultFolder(olFolderInbox)
Set junk = junk.Folders("CN")
Count = 0
For Each myItem In myitems
If TypeOf myItem Is Outlook.MailItem Then
If Right(myItem.To, 4) = ".cn'" Then
myItem.Move junk
Count = Count + 1
End If
End If
Next myItem

Debug.Print Count
Set MyNameSpace = Nothing
Set MyInbox = Nothing
Set myOutbox = Nothing
Set myitems = Nothing
Set junk = Nothing
End Sub

推荐答案

答案在这里: 对于每个循环在Outlook邮箱中循环删除项目时,某些项目会被跳过

The answer was here: For Each loop: Some items get skipped when looping through Outlook mailbox to delete items

感谢@niton

这篇关于搜索已发送的邮件并将多封邮件移至文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆