[英]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
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.