繁体   English   中英

VBA Excel - 在 Outlook 中打开特定文件夹或子文件夹

[英]VBA Excel - Open a specific folder or subfolder in Outlook

我正在尝试从 Excel 中的 VBA 宏打开 outlook。 我能够打开它,但如何让它转到特定文件夹? 比方说“已发送邮件”、“草稿文件夹”等。另外,选择另一个邮箱中的文件夹怎么样? 我的 Outlook 中有两个邮箱。

这是我到目前为止的代码:

Sub my_prov_openOutlook()

Dim oOutlook As Object

On Error Resume Next
Set oOutlook = GetObject(, "Outlook.Application")
On Error GoTo 0

If oOutlook Is Nothing Then
    Shell ("OUTLOOK")
    '''I would like to open a specific folder under the inbox or under a subfolder
Else
    oOutlook.ActiveWindow.Activate
    '''I would like to open a specific folder under the inbox or under a subfolder
End If

不要将GetObject与 Outlook 一起使用 - 使用CreateObject Outlook 是一个单例:如果它已经在运行,您将获得一个指向现有实例的指针。 如果它没有运行,它将启动。 也不要使用On Error Resume Next - 你不会知道你是否收到错误以及错误发生的位置。

Set oOutlook = CreateObject("Outlook.Application")
set oNS = oOutlook.GetNamespace("MAPI")
oNS.Logon 'does not do anything if Outlook is already running
set oFolder = oNS.GetDefaultFolder(6) 'olFolderInbox
if (oOutlook.ActiveExplorer Is Nothing) Then
  oFolder.Display
Else
  set oOutlook.ActiveExplorer = oFolder
End If

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM