我有一些Excel VBA代码,可以搜索Outlook共享子文件夹并检索数据或答复选定的电子邮件。当代码试图将Outlook子文件夹分配给变量时,会发生问题。在远程桌面上运行时,以某种方式,Excel或代码无法识别子文件夹。
如果代码是在本地计算机(运行Windows 10)上运行的,则一切运行正常,但是在远程桌面(运行Windows 7)上运行的代码则无法运行。所有计算机都在运行Office 2016。
我进入了每一行代码,并确定该代码能够读取电子邮件帐户,收件箱文件夹,但无法读取子文件夹。
Sub DataExtract_Template()
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Dim myOlApp As Outlook.Application
Dim myNameSpace As Outlook.Namespace
Dim objOwner As Outlook.Recipient
Dim topOlFolder As Outlook.MAPIFolder
Dim attach As Outlook.Attachment
Dim fdr_Unprocessed As Outlook.MAPIFolder
Dim fdr_Pending As Outlook.MAPIFolder
Dim fdr_Processed As Outlook.MAPIFolder
Set myNameSpace = Outlook.Application.GetNamespace("mapi")
Set objOwner = myNameSpace.CreateRecipient("xxxxxx@xxx.com")
objOwner.Resolve
If objOwner.Resolved Then
Set topOlFolder = myNameSpace.GetSharedDefaultFolder(objOwner, olFolderInbox)
End If
'this is where the code errors out as it can't seem to find the subfolders, but it can recognize the shared folders inbox
Set fdr_Unprocessed = topOlFolder.Folders("RMA - Unprocessed")
Set fdr_Pending = topOlFolder.Folders("RMA - Pending")
Set fdr_Processed = topOlFolder.Folders("RMA - Processed")
代码尝试将子文件夹设置为变量时出现的错误消息是:
运行时错误'-2147221233(8004010f)':尝试的操作失败。找不到对象。
如果您需要其他任何信息,请告诉我。