我收到此 Object Required 错误。请参阅下面的代码。我不明白为什么我会得到它。oitem 变量被声明为一个对象,我在尝试移动它之前对“MailItem”类型进行了测试。请指教。
艾伦
Public StatsArchiveFolder As Outlook.Folder
'StatsArchiveFolder is set to equal an Outlook.Folder elsewhere
_____________________________________
Sub MoveHarpStatMail()
Dim olapp As Outlook.Application
Dim olappns As Outlook.NameSpace
Dim oitem As Object
Dim ItemsToProcess As Outlook.Items
Dim myFolder As MAPIFolder
Dim sFilter As String
Dim tempMailItem As Outlook.MailItem
On Error GoTo LocalErr
'set outlook objects
Set olapp = New Outlook.Application
Set olappns = olapp.GetNamespace("MAPI")
Set myFolder = olappns.GetDefaultFolder(olFolderInbox)
'Filter or only MailItems received today
sFilter = "[ReceivedTime] >= " & AddQuotes(Format(Date, "ddddd"))
Set ItemsToProcess = Session.GetDefaultFolder(olFolderInbox).Items.Restrict(sFilter)
For Each oitem In ItemsToProcess
If TypeName(oitem) = "MailItem" Then
Set tempMailItem = oitem
If CheckSubject(tempMailItem.Subject) Then
MoveToArchiveFolder (tempMailItem) '<<<Error 424 Object Required ???
End If
End If
Next oitem
ExitProc:
Set olapp = Nothing
Set olappns = Nothing
Set myFolder = Nothing
Set ItemsToProcess = Nothing
...
End Sub
_________________________________
Function CheckSubject(Subject As String) As Boolean
If (LCase(Trim(Subject)) = LCase(SubjectTitle)) Then
CheckSubject = True
Else
CheckSubject = False
End If
End Function
______________________________
Sub MoveToArchiveFolder(Item As Outlook.MailItem)
If (ArchiveFolder = Nothing) Then
MsgBox ("The ArchiveFolder object is not set.")
End If
Item.Move (StatsArchiveFolder)
End Sub