我在 VS2010 中编写了这个小程序,可以在 Outlook 2007 上运行。
它适用于收件箱的标准通读,但我无法让它正确指向其他文件夹,我收到“用户代码未处理 COMException”错误,显示“操作失败。找不到对象。 " ...
如果有帮助,我已经包含了我的 Outlook 结构的屏幕截图...
Imports Microsoft.Office.Interop
Public Class ThisAddIn
Private Sub ThisAddIn_Startup() Handles Me.Startup
End Sub
Private Sub ThisAddIn_Shutdown() Handles Me.Shutdown
End Sub
Private Sub Application_Startup() Handles Application.Startup
Dim MyApp As Outlook.Application = New Outlook.Application
Dim MyNS As Outlook.NameSpace = MyApp.GetNamespace("MAPI")
Dim MyInbox As Outlook.MAPIFolder = MyNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)
Dim MyEmails As Integer = MyInbox.Items.Count
Dim MyEMail As Outlook.MailItem
Dim MyCount As Integer
Dim MySubFolder As Outlook.MAPIFolder = MyNS.Folders("Kickabout") **<<< Error occurs here**
For MyCount = MyEmails To 1 Step -1
MyEMail = MyInbox.Items(MyCount)
If MyEMail.SenderEmailAddress = "MrX@abc.com" Then
If MyEMail.Attachments.Count > 0 Then
MySubFolder = MyNS.Folders("Kickabout\Attachments")
End If
MyEMail.Move(MySubFolder)
End If
Next
End Sub
End Class