vba 将 MailItem 移动到指定文件夹
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15819769/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Move MailItem to specified folder
提问by finaccio
Can someone help me with this small script I am trying to implement in VBA?
有人可以帮助我使用我试图在 VBA 中实现的这个小脚本吗?
What appends is that the loop randomly stops and I can not move all the mail in "archivio" folder.
附加的是循环随机停止,我无法移动“archivio”文件夹中的所有邮件。
Private Sub aggiorna_click()
Dim x As Object
Dim ns As Outlook.NameSpace
Dim itm, sgsa, actionPlan, cartella, specCartella As Object
Dim olDestFolder As Outlook.MAPIFolder
Set ns = GetNamespace("MAPI")
Set itm = ns.GetDefaultFolder(olFolderInbox)
Set sgsa = itm.Folders("SGSA")
Set actionPlan = sgsa.Folders("action plan")
Set cartella = actionPlan.Folders(tipo.Text)
Set specCartella = cartella.Folders(piano.Text)
Set olDestFolder = itm.Folders("archivio")
For Each x In specCartella.Items
x.Move olDestFolder
Next x
End Sub
回答by Kazimierz Jawor
according to comments under the question, the new loop could look like this one (not tested)
根据问题下的评论,新循环可能看起来像这样(未测试)
Dim i As Long
For i = specCartella.Items.Count to 1 Step -1
specCartella.Items(i).Move olDestFolder
Next i
(i have just changed x with i!)
(我刚刚用 i 改变了 x!)