[英]Get MAPI Folder in Outlook from Folder Path
我正在尝试使用此页面上的功能: http : //www.outlookcode.com/d/code/getfolder.htm使用文件夹路径导航到文件夹。 (我会把这个代码复制到这个问题的底部 - 我原样使用它,完全没有修改。)我需要使用它的原因是Outlook中的默认收件箱与我需要的收件箱不同积极点。 通过右键单击并点击属性并查看位置,我知道相关收件箱的路径。
这是我使用的代码:
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,对象变量或未设置块变量。
我不知道这是什么意思。 如果你可以帮我解决这个错误,那就太棒了,如果你有办法让我完全避免这个问题,那也会很棒。 谢谢!
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
我找到了答案。 事实证明这是愚蠢的事情,按照惯例:)
Set Inbox = GetFolder("\\itadmin@email.org\inbox")
需要是
Set Inbox = GetFolder("itadmin@email.org/inbox")
。 这解决了这个问题。 我想我会留下这个以防万一其他人有这个问题,解决方案只是遵循给定的格式...
只需添加此行...
strFolderPath = Replace(strFolderPath,“\\\\”,“”)
显然也需要这一行:
strFolderPath = Replace(strFolderPath, "\", "/")
但是在上一行之后。
因此,在上下文中:
strFolderPath = Replace(strFolderPath, "\\", "")
strFolderPath = Replace(strFolderPath, "\", "/")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.