从文件夹路径在Outlook中获取MAPI文件夹 [英] Get MAPI Folder in Outlook from Folder Path
问题描述
我正在尝试使用此页面上的功能: http://www. outlookcode.com/d/code/getfolder.htm 使用文件夹路径导航到文件夹. (我会将代码复制到这个问题的底部,因为我原样使用它,完全没有修改.)之所以需要使用它,是因为Outlook中的默认收件箱与我需要的收件箱不同积极点.通过右键单击相关收件箱并点击属性,然后查看其位置,我知道了该收件箱的路径.
I am trying to use the function from on this page: http://www.outlookcode.com/d/code/getfolder.htm to use the folder path to navigate to a folder. (I will copy that code onto the bottom of this question--I used it as-is, unmodified at all.) The reason I need to use this is that the default inbox in Outlook is not the same as the inbox I need to be active. I know the path of the relevant inbox by right clicking on it and hit properties, and looking at location.
这是我使用的代码:
Set objOutlook = CreateObject("Outlook.Application", "localhost")
Set objNamespace = objOutlook.GetNamespace("MAPI")
Set Inbox = GetFolder("\\itadmin@email.org\inbox")
Debug.Print Inbox '<-- This fails
Set InboxItems = Inbox.Items '<-- This also fails
InboxItems.SetColumns ("SentOn")
这将返回运行时错误91,对象变量或未设置带块变量.
This returns runtime error 91, Object variable or With block variable not set.
我不知道这意味着什么.如果您可以帮助我解决此错误,那将是非常棒的,并且如果您有一种方法可以完全避免此问题,那也将是非常棒的.谢谢!
I have no idea what this means. If you could help me solve this error, that would be awesome, and if you have a way that I could avoid this problem entirely, that would be awesome also. Thanks!
Public Function GetFolder(strFolderPath As String)As MAPIFolder
' strFolderPath needs to be something like
' "Public Folders\All Public Folders\Company\Sales" or
' "Personal Folders\Inbox\My Folder"
Dim objApp As Outlook.Application
Dim objNS As Outlook.NameSpace
Dim colFolders As Outlook.Folders
Dim objFolder As Outlook.MAPIFolder
Dim arrFolders() As String
Dim I As Long
On Error Resume Next
strFolderPath = Replace(strFolderPath, "/", "\")
arrFolders() = Split(strFolderPath, "\")
Set objApp = Application
Set objNS = objApp.GetNamespace("MAPI")
Set objFolder = objNS.Folders.Item(arrFolders(0))
If Not objFolder Is Nothing Then
For I = 1 To UBound(arrFolders)
Set colFolders = objFolder.Folders
Set objFolder = Nothing
Set objFolder = colFolders.Item(arrFolders(I))
If objFolder Is Nothing Then
Exit For
End If
Next
End If
Set GetFolder = objFolder
Set colFolders = Nothing
Set objNS = Nothing
Set objApp = Nothing
End Function
推荐答案
我找到了答案.原来这很愚蠢,像往常一样:)
I found the answer. Turns out it's something stupid, as per usual :)
Set Inbox = GetFolder("\\itadmin@email.org\inbox")
需要成为
Set Inbox = GetFolder("itadmin@email.org/inbox")
.这样可以解决问题.我想如果有其他人遇到这个问题,我会把它留在这里,解决方案就是按照给定的格式...
. This fixes the problem. I figured I would leave this here in case anyone else has this problem, the solution is simply to follow the given format...
这篇关于从文件夹路径在Outlook中获取MAPI文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!