我正在尝试为 Outlook 2010 编写一个加载项,它将遍历特定邮件文件夹中的所有项目并从那里自动填充 Excel 电子表格。目前,我什至无法访问默认收件箱。我正在从 Visual Studio 2010 Pro 编写加载项,并根据需要使用自动完成选项。我的问题是,每当我运行我的代码时,即使只是设置基本变量,它也会给我一个“找不到对象”错误并引发异常。我不知道出了什么问题,我将非常感谢任何帮助。
Imports Microsoft.Office.Interop
Public Class ThisAddIn
Private Sub ThisAddIn_Startup() Handles Me.Startup
Dim olApp As Outlook.Application
Dim olNamespace As Outlook.NameSpace
Dim olFolders As Object
Dim olReadFolder As Outlook.Folder
Dim readCollection As Microsoft.Office.Interop.Outlook.Items
Dim currentMessage As Outlook.MailItem
Dim exWorksheet As Excel.Worksheet
olApp = New Outlook.Application
olNamespace = olApp.GetNamespace("MAPI")
'olFolders = olNamespace.Folders
olReadFolder = olNamespace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox) '<-- Add-in fails here
End Sub
Private Sub ThisAddIn_Shutdown() Handles Me.Shutdown
End Sub
End Class