Folder on root, not under Inbox generates error: The attempted operation failed. An Object Could not be found
Folder on root, not under Inbox generates error: The attempted operation failed. An Object Could not be found
我在根目录下创建了一个文件夹,而不是在收件箱下。移动到根文件夹的语法是什么?
我遇到错误:
The attempted operation failed
An Object Could not be found
调试指向下面一行myRestrictItems(i).Move myFolder.folders("Business")
Option Explicit
Public Sub Example()
Dim myNamespace As Outlook.NameSpace
Dim myFolder As Outlook.MAPIFolder
Dim myRestrictItems As Outlook.Items
Dim myItems As Outlook.Items
Dim myItem As Object
Dim i As Long
Dim Filter As String
Dim Msg As String
Set myNamespace = Application.GetNamespace("MAPI")
Set myFolder = myNamespace.GetDefaultFolder(olFolderInbox)
Set myItems = myFolder.Items
Filter = "@SQL=" & Chr(34) & "urn:schemas:httpmail:datereceived" & _
Chr(34) & " >= '01/01/2018' And " & _
Chr(34) & "urn:schemas:httpmail:datereceived" & _
Chr(34) & " < '23/03/2018' And " & _
Chr(34) & "urn:schemas:httpmail:fromname" & _
Chr(34) & "Like '%Jayakumar Krishnamoorthy%'"
Set myRestrictItems = myItems.Restrict(Filter)
For i = myRestrictItems.Count To 1 Step -1
myRestrictItems(i).Move myFolder.folders("Business")
'Msg = myRestrictItems.Count & " Items in " & myFolder.Name & " Folder"
'MsgBox (Msg)
Next
End Sub
运行 快速循环浏览文件夹以 debug.print
它们的名称和您可能认为有用的任何其他属性。显示名称和内部名称可能不同。
正确的语法应该是
myRestrictItems(i).Move myNamespace.Folders("Business")
也把你msgbox
移到循环外,例子
Set myRestrictItems = myItems.Restrict(Filter)
Msg = myRestrictItems.Count & " Items in " & myFolder.Name & " Folder, Move it?"
If MsgBox(Msg, vbYesNo) = vbYes Then
For i = myRestrictItems.Count To 1 Step -1
myRestrictItems(i).Move myNamespace.Folders("Business")
Next
End If
我在根目录下创建了一个文件夹,而不是在收件箱下。移动到根文件夹的语法是什么?
我遇到错误:
The attempted operation failed
An Object Could not be found
调试指向下面一行myRestrictItems(i).Move myFolder.folders("Business")
Option Explicit
Public Sub Example()
Dim myNamespace As Outlook.NameSpace
Dim myFolder As Outlook.MAPIFolder
Dim myRestrictItems As Outlook.Items
Dim myItems As Outlook.Items
Dim myItem As Object
Dim i As Long
Dim Filter As String
Dim Msg As String
Set myNamespace = Application.GetNamespace("MAPI")
Set myFolder = myNamespace.GetDefaultFolder(olFolderInbox)
Set myItems = myFolder.Items
Filter = "@SQL=" & Chr(34) & "urn:schemas:httpmail:datereceived" & _
Chr(34) & " >= '01/01/2018' And " & _
Chr(34) & "urn:schemas:httpmail:datereceived" & _
Chr(34) & " < '23/03/2018' And " & _
Chr(34) & "urn:schemas:httpmail:fromname" & _
Chr(34) & "Like '%Jayakumar Krishnamoorthy%'"
Set myRestrictItems = myItems.Restrict(Filter)
For i = myRestrictItems.Count To 1 Step -1
myRestrictItems(i).Move myFolder.folders("Business")
'Msg = myRestrictItems.Count & " Items in " & myFolder.Name & " Folder"
'MsgBox (Msg)
Next
End Sub
运行 快速循环浏览文件夹以 debug.print
它们的名称和您可能认为有用的任何其他属性。显示名称和内部名称可能不同。
正确的语法应该是
myRestrictItems(i).Move myNamespace.Folders("Business")
也把你msgbox
移到循环外,例子
Set myRestrictItems = myItems.Restrict(Filter)
Msg = myRestrictItems.Count & " Items in " & myFolder.Name & " Folder, Move it?"
If MsgBox(Msg, vbYesNo) = vbYes Then
For i = myRestrictItems.Count To 1 Step -1
myRestrictItems(i).Move myNamespace.Folders("Business")
Next
End If