从文件夹路径获取 Outlook 中的 MAPI 文件夹 [英] Get MAPI Folder in Outlook from Folder Path

查看:45
本文介绍了从文件夹路径获取 Outlook 中的 MAPI 文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用此页面上的功能: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.orginbox")
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 FoldersAll Public FoldersCompanySales" or
  '   "Personal FoldersInboxMy 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.orginbox")

必须

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆