简体   繁体   English

从 Excel 宏打开特定 Outlook 文件夹

[英]Open Specific Outlook Folder From Excel macro

在此处输入图像描述

I have a macro in Excel, which allows me to select the outlook folder inbox of my main inbox.我在 Excel 中有一个宏,它允许我在我的主收件箱的 outlook 文件夹收件箱中访问 select。 However I would like to modify it in order to be able to select any specific folder (or subfolder) in my inbox.但是我想修改它,以便能够 select 在我的收件箱中的任何特定文件夹(或子文件夹)。 For example, I would like to modify my macro in order that when I run it, it selects the subfolder “ALD” on screenshot enclosed.例如,我想修改我的宏,以便当我运行它时,它会在随附的屏幕截图中选择子文件夹“ALD”。 If someone know how to do it, that would be great!如果有人知道该怎么做,那就太好了!

Moreover, I have also another email in my outlook constituted with a lot of folders and subfolders (the one on the screenshot enclosed corresponds to my main email, this other email does not appear on the screenshot enclosed), I would like to be able to modify my macro in order to select any specific folder or subfolder of this other mail. Moreover, I have also another email in my outlook constituted with a lot of folders and subfolders (the one on the screenshot enclosed corresponds to my main email, this other email does not appear on the screenshot enclosed), I would like to be able to修改我的宏以 select 此其他邮件的任何特定文件夹或子文件夹。 Let´s say for example I have another email in my outlook called xxxx@yyyy.com and a folder called “aaaa” and inside a subfolder called “bbbb”, how should I modify my macro in order that when running it, it selects me the subfolder “bbbb”?假设我在我的 outlook 中有另一个 email,名为 xxxx@yyyy.com 和一个名为“aaaaa”的文件夹,我应该在子文件夹中修改我的宏我的子文件夹“bbbb”? Please find the code of my macro below.请在下面找到我的宏的代码。 Thanks in advance.提前致谢。

Sub OpenOutlookFolder()
Dim xOutlookApp As Outlook.Application
Dim xNameSpace As Outlook.Namespace
Dim xFolder As Outlook.Folder
Dim xFolderType As OlDefaultFolders
On Error Resume Next

Set xOutlookApp = New Outlook.Application
Set xNameSpace = xOutlookApp.Session
Set xFolder = xNameSpace.GetDefaultFolder(olFolderInbox
xFolder.Display
Set xFolder = Nothing
Set xNameSpace = Nothing
Set xOutlookApp = Nothing
Exit Sub
End Sub

Something along the lines of:类似于以下内容:

Dim ThisNamespace As Outlook.NameSpace: Set ThisNamespace = Application.GetNamespace("MAPI")
Dim Inbox As Outlook.MAPIFolder: Set Inbox = ThisNamespace.GetDefaultFolder(olFolderInbox)

Dim BaseFolder As Outlook.MAPIFolder: Set BaseFolder = Inbox '.Folders("SubFolder1\SubFolder2...")

For direct subfolder access, uncomment within the last line and update the path对于直接子文件夹访问,取消最后一行中的注释并更新路径

If you want to create a folder structure which is searchable/editable then my answer in this question may be of interest: How can one iterate through the subfolders of a subfolder of a shared mail inbox folder?如果您想创建一个可搜索/可编辑的文件夹结构,那么我对这个问题的回答可能会很有趣: 如何遍历共享邮件收件箱文件夹的子文件夹的子文件夹?

Finally by checking again the link Get reference to additional Inbox, I managed to modify my macro in order it works and does as I want.最后,通过再次检查链接获取对附加收件箱的引用,我设法修改了我的宏,以便它按我的意愿工作和执行。 Please find the code below:请在下面找到代码:

Sub OpenOutlookFolderworks()

Dim xOutlookApp As Outlook.Application将 xOutlookApp 调暗为 Outlook.Application

Dim xNameSpace As Outlook.Namespace
Dim xFolder As Outlook.Folder
 Dim vRecipient As Outlook.MAPIFolder
 Dim xFolderType As OlDefaultFolders
On Error Resume Next
Set xOutlookApp = New Outlook.Application
Set xNameSpace = xOutlookApp.Session
Set xFolder = xNameSpace.GetDefaultFolder(olFolderInbox)
Set xFolder = xFolder.Folders("payment office")
Set xFolder = xFolder.Folders("JIRA")
xFolder.display
Set xFolder = Nothing
Set xNameSpace = Nothing
Exit Sub
End Sub

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

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