访问 Outlook 默认文件夹 [英] Access Outlook default folder
问题描述
我正在处理 Outlook VBA 应用程序,我需要访问我的收件箱,但我似乎遇到了一些问题.我正在使用 GetDefaultFoldder(olFolderInbox)
方法,但是,我设置了多个电子邮件地址,但没有一个显示在我的个人文件夹的收件箱中.
I working on an Outlook VBA application and I need to access my inbox but I seem to be having some trouble. I am using the GetDefaultFoldder(olFolderInbox)
method, however, I have several email addresses set up and none of them show up in my personal folder's inbox.
所以我的问题是,这个默认文件夹是在哪里定义的?我怎么知道哪个收件箱是默认收件箱?我知道还有 GetFolderFromID
方法,如果我要使用它,
So my question is, where is this default folder defined? How do I know which inbox is the default one? I know there is also the GetFolderFromID
method, if I were to use this,
如何找到文件夹 ID 以指向它?
how can I find a folders ID in order to point to it?
这是我正在使用的代码.这是来自 Timothy Chen Allen 博客的教程,如下所示 蒂莫西的博客.代码:
Here is the code I am using. This is from a tutorial on Timothy Chen Allen's blog as seen here Timothy's Blog. The code:
Sub find_unread()
On Error GoTo eh:
Dim ns As Outlook.NameSpace
Dim folder As MAPIFolder
Dim item As Object
Dim msg As MailItem
Set ns = Session.Application.GetNamespace("MAPI")
Set folder = ns.GetDefaultFolder(olFolderInbox)
For Each item In folder.Items
DoEvents
If (item.Class = olMail) And (item.UnRead) Then
Set msg = item
Debug.Print msg.SenderEmailAddress
msg.Display True
End If
Next
MsgBox "All messages in Inbox are read", vbInformation, "All Read"
Exit Sub
eh:
MsgBox Err.Description, vbCritical, Err.Number
End Sub
推荐答案
您可以使用 Folders 属性,并将多个 Folders 属性串在一起,以获取命名空间中的任何文件夹.一些例子
You can use the Folders property, and string multiple Folders properties together, to get at any folder in the namespace. Some examples
收件箱(与 GetDefaultFolder(olInbox) 相同)
The Inbox (same as GetDefaultFolder(olInbox))
ns.Folders("Personal Folders").Folders("Inbox")
Inbox 的一个名为 Backup 的子文件夹
A subfolder of Inbox named Backup
ns.Folders("Personal Folders").Folders("Inbox").Folders("Backup")
与个人文件夹处于同一级别的其他收件箱
The OtherInbox at the same level as Personal Folders
ns.Folders("OtherInbox")
GetDefaultFolder 非常适合快速访问默认文件夹,但如果您需要默认文件夹以外的其他内容,只需使用 NameSpace 对象的 Folders 属性向下导航即可.
The GetDefaultFolder is good for quickly getting to a default folder, but if you need something other than the default, just navigate down the tree with the Folders property of the NameSpace object.
这篇关于访问 Outlook 默认文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!