vba 获取对其他收件箱的引用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9076634/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 12:30:11  来源:igfitidea点击:

Get reference to additional Inbox

vbaoutlookoutlook-vba

提问by Mark

I'm using Outlook 2007 - and have my main mailbox: Tait, Mark

我使用的是 Outlook 2007 - 并且有我的主邮箱:Tait, Mark

I have also added another mailbox to my profile: Procurement, Request

我还在我的个人资料中添加了另一个邮箱:采购、请求

Both appear as top level folders within Outlook:

两者都显示为 Outlook 中的顶级文件夹:

Mailbox - Tait, Mark> -Conversation History
-Deleted Items
-Drafts
-Inbox
-Junk E-Mail

Mailbox - Procurement, Request
--Conversation History
--Deleted Items
--Drafts
--Inbox
--Junk E-Mail

邮箱 - Tait、Mark> - 对话历史 - 已删除的
项目 -
草稿 -
收件
箱 - 垃圾邮件

邮箱 - 采购、请求 --
对话历史
-- 已删除的项目--草稿--
收件
箱 --
垃圾邮件

I can get a reference to my default Inbox (Tait, Mark) using:
Set Inbox = ns.GetDefaultFolder(olFolderInbox)

我可以使用以下方法获取对我的默认收件箱(Tait、Mark)的引用:
Set Inbox = ns.GetDefaultFolder(olFolderInbox)

How do I get a reference to the Inbox in the "Procurement, Request" mailbox?

如何在“采购、请求”邮箱中获得对收件箱的引用?

采纳答案by brettdj

Something like this should do the trick

像这样的事情应该可以解决问题

Dim objNS As Outlook.NameSpace
Dim objFolder As Outlook.MAPIFolder
Set objNS = GetNamespace("MAPI")
Set objFolder = objNS.Folders("Procurement, Request")
Set objFolder = objFolder.Folders("Inbox")

This link has some useful code for handling different Inboxes- it may be of interest

此链接有一些用于处理不同收件箱的有用代码- 它可能会引起您的兴趣

回答by Bruno

Dim olNS As NameSpace
Dim InputFolder As Outlook.MAPIFolder
Set olNS = Outlook.Application.GetNamespace("MAPI")

' Get reference to folder in users Mailbox for Input
Set InputFolder = olNS.Folders("Procurement, Request").Folders("Inbox")

' all the emails in the shared inbox are represented by:
InputFolder.Items

回答by Dmitry Streblechenko

Use Namespace.GetSharedDefaultFolder. It will work even if the mailbox is not opened in the current profile. You still need to have the right to open the mailbox and access the folder in question of course:

使用Namespace.GetSharedDefaultFolder. 即使未在当前配置文件中打开邮箱,它也会工作。当然,您仍然需要有权打开邮箱并访问有问题的文件夹:

Set vNamespace = Application.GetNamespace("MAPI")
set vRecipient = vNamespace.CreateRecipient("Procurement, Request")
if vRecipient.Resolve Then
  set vFolder = vNamespace.GetSharedDefaultFolder(vRecipient, olFolderInbox)
End If

If you need to open the other user's mailbox (with all off its folders), you can use Redemptionand its RDOSession.GetSharedMailbox method:

如果您需要打开其他用户的邮箱(所有文件夹都关闭),您可以使用Redemption及其RDOSession.GetSharedMailbox 方法:

 set Session = CreateObject("Redemption.RDOSession")
 Session.MAPIOBJECT = Application.Session.MAPIOBJECT
 set Store = Session.GetSharedMailbox("Procurement, Request")
 set vFolder = Store.GetDefaultFolder(olFolderInbox)
 MsgBox "The address of the mailbox owner: " & Store.Owner.Address