我正在尝试使用此页面上的功能: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