|
本帖最后由 dsd999 于 2012-2-28 17:01 编辑
各位老师,我有以下这段代码,想实现的功能是,当收到一个题目为"abcdefg“的邮件时,自动将这个邮件移到Archives目录,代码中用junk变量来代表这个目录,但运行时系统总提示Type mismatch。请各位高手帮忙看一下。谢谢。
Private Sub Application_NewMail()
Dim filter As String
filter = "abcdefg"
Dim outlookNameSpace As Outlook.NameSpace
Set outlookNameSpace = Outlook.Application.GetNamespace("MAPI")
Dim inbox As Outlook.MAPIFolder
Set inbox = outlookNameSpace.GetDefaultFolder( _
Outlook.OlDefaultFolders.olFolderInbox)
Dim items As Outlook.items
Set items = inbox.items
Dim junk As Outlook.MAPIFolder
Set junk = Application.GetNamespace("MAPI").Folders("Archive Folders")
'outlookNameSpace.GetDefaultFolder ( _
Outlook.OlDefaultFolders.olFolderJunk)
items.Restrict ("[Unread] = true")
' If the mail item matches the specified filter,
' move it to the junk e-mail folder.
Dim mail As Outlook.MailItem
For Each mail In items
If mail.Subject = filter Then
MsgBox ("find it")
mail.Move junk
End If
Next
End Sub
|
|