简体   繁体   English

将已读项目从文件夹移回收件箱

[英]Moving read items from a folder back to inbox

I'm new to VBA and looking for a way to move read emails from a folder called "ForApproval" back into Inbox.我是 VBA 新手,正在寻找一种方法将已读电子邮件从名为“ForApproval”的文件夹移回收件箱。 Found this code on Stack and it works brilliantly, but when I try to reverse source and destination and put my folder name in - I'm getting: Run-time error '424': Object Required (see below screenshot)Stack上找到了这段代码,它工作得很好,但是当我尝试反转源和目标并将我的文件夹名称放入时 - 我得到:运行时错误“424”:需要对象(见下面的截图)

Can someone have a quick look and say what's wrong in here?有人可以快速浏览一下并说出这里有什么问题吗?

Original Code:原始代码:

    Sub ReadMailMover()

    Set objOutlook = CreateObject("Outlook.Application")  

    Set objNamespace = objOutlook.GetNamespace("MAPI")  

    **Set objFolderSrc = objNamespace.GetDefaultFolder(olFolderInbox)**

    **Set objFolderDst = objFolderSrc.Parent.folders("__Reviewed")**  

    Set colitems = objFolderSrc.Items  

    Set colfiltereditems = colitems.Restrict("[UnRead] = False")  

    For intMessage = colfiltereditems.Count To 1 Step -1  

    colfiltereditems(intMessage).Move objFolderDst  

    Next  

    End Sub 

My reversed version:我的反向版本:

Sub ReadMailMover()

Set objOutlook = CreateObject("Outlook.Application")

Set objNamespace = objOutlook.GetNamespace("MAPI")

**Set objFolderSrc = objFolderSrc.Parent.Folders("ForApproval")**

**Set objFolderDst = objNamespace.GetDefaultFolder(olFolderInbox)**

Set colitems = objFolderSrc.Items

Set colfiltereditems = colitems.Restrict("[UnRead] = False")

For intMessage = colfiltereditems.Count To 1 Step -1

colfiltereditems(intMessage).Move objFolderDst

Next

End Sub

在此处输入图片说明

Runtime Error I'm getting我得到的运行时错误

In the reversed code, when you initialise your variable objFolderSrc it includes a reference to itself.在反向代码中,当您初始化变量objFolderSrc 时,它包含对自身的引用。

Set objFolderSrc = objFolderSrc.Parent.Folders("ForApproval")

At this point objFolderSrc is uninitialized.此时objFolderSrc未初始化。 It doesn't reference anything.它不引用任何东西。 For this reason it cannot be used to define a location.因此,它不能用于定义位置。

Try this instead:试试这个:

Set objFolderSrc = application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Parent.Folders("ForApproval")

Here the circular reference has been replaced.这里循环引用已被替换。 You source folder is referenced via the inbox.您的源文件夹是通过收件箱引用的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将邮件从收件箱移动到特定文件夹 - Moving a mail from inbox to a specific folder 如何将具有特定主题的 Outlook 收件箱中的邮件项目移动到特定文件夹/子文件夹? - How can I move Mails Items from Outlook Inbox with specific subject to specific folder/sub folder? 将带有指定附件的电子邮件从共享收件箱移动到同一共享邮箱的不同文件夹 - Moving emails with specified attachments from shared inbox to a different folder of the same shared mailbox 从收件箱中删除电子邮件,并通过规则-> 脚本从已删除项目文件夹中删除它 - Delete email from inbox and also delete it from deleted-items folder via rule->script 用于将邮件从收件箱移动到 Outlook 中的存档的热键 - Hotkey for moving messages from inbox to archive in Outlook 将 email 从共享收件箱移动到子文件夹 - Moving an email from a shared Inbox to a subfolder 如何从 Outlook 收件箱中读取邮件失败项目以将其保存在 Excel 工作表中 - How to read mail failure items from Outlook inbox to save them in an excel sheet 如果特定收件箱文件夹达到 20 个项目,则发出警告通知 - Warning Notification if specific inbox folder reaches 20 items 将邮件从子文件夹移动到收件箱时捕获事件 - Capture the event while moving the mail from subfolder to inbox 在收件箱中查找特定日期的电子邮件并将其移动到新文件夹 - Find emails in inbox from a specific date and move them to a new folder
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM