Outlook 使用 GetSharedDefaultFolder 自动化错误在 SharedMailbox 中选择子文件夹 [英] Outlook Selecting a Subfolder in the SharedMailbox using GetSharedDefaultFolder Automation error
问题描述
以下代码用于计算特定SharedMailbox
或其子文件夹
中的电子邮件数量.
The following code is to count the number of emails in a particular SharedMailbox
or its subfolder
.
我在 SharedMailbox 中选择子文件夹时遇到问题.我已经阅读了许多关于 GetSharedDefaultFolder 的资源,包括 这个一>.
I am having trouble selecting a subfolder in SharedMailbox. I have read a number of resources on GetSharedDefaultFolder including this one.
然而,努力把它正确地组合在一起.如果你能帮上忙,那就太好了.
However, struggling to put it together correctly. Would be really great if you could help with this.
我在运行代码时遇到以下错误.
I am experiencing the following error while running the code.
运行时错误 '-2147221233 (80040010f)' 自动化错误
Run-time error '-2147221233 (80040010f)' Automation error
Sub CountInboxSubjects()
Dim olApp As Outlook.Application
Dim olNs As Outlook.Namespace
Dim olFldr As Outlook.MAPIFolder
Dim MyFolder1 As Outlook.MAPIFolder
Dim MyFolder2 As Outlook.MAPIFolder
Dim MyFolder3 As Outlook.MAPIFolder
Dim olMailItem As Outlook.MailItem
Dim propertyAccessor As Outlook.propertyAccessor
Dim olItem As Object
Dim dic As Dictionary
Dim i As Long
Dim Subject As String
Dim val1 As Variant
Dim val2 As Variant
val1 = ThisWorkbook.Worksheets("Data").Range("I2")
val2 = ThisWorkbook.Worksheets("Data").Range("I3")
Set olApp = New Outlook.Application
Set olNs = olApp.GetNamespace("MAPI")
'Set olFldr = olNs.GetDefaultFolder(olFolderInbox)
Set olShareName = olNs.CreateRecipient("Shared_MailBox")
Set olFldr = olNs.GetSharedDefaultFolder(olShareName, olFolderInbox)
MsgBox (olFldr)
Set MyFolder1 = olFldr.Folders("Sub_Folder")
MsgBox (MyFolder1)
Set MyFolder2 = MyFolder1.Folders("Sub_Sub_Folder")
MsgBox (MyFolder2)
Set MyFolder3 = MyFolder1.Folders("Sub_Sub_Folder2")
MsgBox (MyFolder3)
If ThisWorkbook.Worksheets("EPI_Data").Range("I5") = "Inbox" Then
MyFolder = olFldr
ElseIf ThisWorkbook.Worksheets("EPI_Data").Range("I5") = "Sub_Folder" Then
MyFolder = MyFolder1
ElseIf ThisWorkbook.Worksheets("EPI_Data").Range("I5") = "Sub_Sub_Folder" Then
MyFolder = MyFolder2
ElseIf ThisWorkbook.Worksheets("EPI_Data").Range("I5") = "Sub_Sub_Folder" Then
MyFolder = MyFolder3
End If
Set olItem = MyFolder.Items
'Set myRestrictItems = olItem.Restrict("[ReceivedTime]>'" & Format$("01/01/2019 00:00AM", "General Date") & "' And [ReceivedTime]<'" & Format$("01/02/2019 00:00AM", "General Date") & "'")
Set myRestrictItems = olItem.Restrict("[ReceivedTime]>'" & Format$(val1, "General Date") & "' And [ReceivedTime]<'" & Format$(val2, "General Date") & "'")
For Each olItem In myRestrictItems
If olItem.Class = olMail Then
Set propertyAccessor = olItem.propertyAccessor
Subject = propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x0E1D001E")
If dic.Exists(Subject) Then dic(Subject) = dic(Subject) + 1 Else dic(Subject) = 1
End If
Next olItem
With ActiveSheet
.Columns("A:B").Clear
.Range("A1:B1").Value = Array("Count", "Subject")
For i = 0 To dic.Count - 1
.Cells(i + 2, "A") = dic.Items()(i)
.Cells(i + 2, "B") = dic.Keys()(i)
Next
End With
End Sub
排除故障后,我知道以下步骤存在问题.
After trouble-shooting, I am aware the following step has issues.
Set MyFolder1 = olFldr.Folders("Sub_Folder")
MsgBox (MyFolder1)
我希望 msgbox 会返回子文件夹名称,但它报告错误.
I expect the msgbox will return the subfolder name but it's reporting error.
运行时错误 '-2147221233 (80040010f)' 自动化错误
Run-time error '-2147221233 (80040010f)' Automation error
我不知道为什么.任何人都可以帮忙..
I couldn't find out why. can anyone please help..
推荐答案
当然,在访问共享文件夹之前,您必须根据地址簿解析收件人的姓名或地址.
Of course, you must resolve a recipient's name or address against the address book before accessing shared folders.
Set olApp = New Outlook.Application
Set olNs = olApp.GetNamespace("MAPI")
Set olShareName = olNs.CreateRecipient("Shared_MailBox")
olShareName.Resolve
If Recip.Resolved Then
Set olFldr = olNs.GetSharedDefaultFolder(olShareName, olFolderInbox)
...
End If
但是访问子文件夹问题的原因是不同的...
But the cause of the issue with accessing a subfolder is different...
首先,尝试取消选中 Exchange 帐户属性对话框的 Advanced 选项卡
上选中的 Download shared folder
复选框.请参阅检测下载共享"文件夹'已在 Outlook 中检查文章了解更多信息.
First of all, try to uncheck Download shared folders
checkbox checked on the Advanced tab
of your Exchange account properties dialog. See the Detecting if ‘Download Shared Folders’ is Checked in Outlook article for more information.
第二,请看默认情况下,共享邮件文件夹在Outlook中以缓存模式下载2010 和展望 2013 文章.您为 PC 上的 CacheOthersMail
键设置了什么值?
Second, please take a look at the By default, shared mail folders are downloaded in Cached mode in Outlook 2010 and Outlook 2013 article. What value do you have set for the CacheOthersMail
key on the PC?
参见 访问共享邮箱中的子文件夹 了解更多信息.
See Accessing subfolders within shared mailbox for more information.
这篇关于Outlook 使用 GetSharedDefaultFolder 自动化错误在 SharedMailbox 中选择子文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!