【发布时间】:2018-11-20 23:33:41
【问题描述】:
我在 Outlook 中有一些 VBA 代码,它在主邮箱中表现完美 - 但是当我添加辅助邮箱时,相同的代码正在挣扎 - 这是 Outlook 2016。
阅读子文件夹似乎很困难 - 我可以让它阅读收件箱中的邮件,但不能阅读子文件夹。
代码:
Dim sharedemail As Outlook.Recipient
Dim myOlApp As New Outlook.Application
Dim myNameSpace As Outlook.NameSpace
Dim myInbox As Outlook.MAPIFolder
Dim myDestFolder Outlook.MAPIFolder
Dim strSubject As String
Dim i As Integer
Set myNameSpace = myOlApp.GetNamespace("MAPI")
Set sharedemail = myNameSpace.CreateRecipient("recip@domain.com")
Set myInbox = myNameSpace.GetSharedDefaultFolder(sharedemail, olFolderInbox)
For itemCount = myInbox.items.Count To 1 Step -1 'Iterates from the end backwards
Set item = myInbox.items(itemCount)
strSubject = UCase(item.Subject)
Select Case True
Case InStr(strSubject, UCase("Holiday Request")) > 0
'Set destination folder
Set myDestFolder = myInbox.Folders("HolidayRequests")
'move the email out of inbox
item.Move myDestFolder
End Select
Next
它停在 Set myDestFolder 行,因为它似乎无法选择该子文件夹 - 正如我所说,相同的代码似乎在主收件箱中工作正常?
谢谢
【问题讨论】: