如何从 Outlook 中的特定电子邮件文件夹中获取 VBA 中的 "CC" 个电子邮件地址?

How to get the "CC" email addresses in VBA from a specific email folder in Outlook?

有人知道如何使用 VBA 从 Outlook 文件夹中的邮件中检索抄送电子邮件地址吗?我已经尝试了我发现的以下代码,但我似乎无法正常工作,因为我遇到了这个错误

Sub CC_EMAIL()
Dim lngCounter As Long
lngCounter = 2
Const PR_EMAIL = &H39FE001E
ThisWorkbook.Sheets(1).Cells(1, 1).Value = "CC Name"
ThisWorkbook.Sheets(1).Cells(1, 2).Value = "CC Email"
'ThisWorkbook.Sheets(1).Cells(1, 3).Value = "Cc-Recipients"
Set objOL = CreateObject("Outlook.Application")
Set objMsg = objOL.ActiveInspector.CurrentItem
Set objSmail = CreateObject("Redemption.SafeMailItem")
objSmail.Item = objMsg
    For Each recip In objSmail.Recipients
        If InStr(objSmail.CC, recip.Name) Then
            ThisWorkbook.Sheets(1).Cells(lngCounter, 1).Value = recip.Name
            ThisWorkbook.Sheets(1).Cells(lngCounter, 2).Value = recip.Fields(PR_EMAIL)
            'ThisWorkbook.Sheets(1).Cells(lngCounter, 3).Value = objSmail.CC
            lngCounter = lngCounter + 1
        End If
    Next
End Sub

首先,检查 objOL.ActiveInspector 是否为空。只有在单独的检查器中显示电子邮件时,它才会退出。

其次,要测试收件人是否是抄送,请使用Type 属性。换行

If InStr(objSmail.CC, recip.Name) Then

If recip.Type = 2 Then '2 is olCC