简体   繁体   中英

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

anyone know how to retrieve CC email addresses from a mail in an Outlook folder using VBA? I have tried the below codes I've found but I can't seem to make it work as I'm having this error在此处输入图像描述

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

Firstly, check that objOL.ActiveInspector is not null. It will exits only if there an email shown in a separate inspector.

Secondly, to test whether a recipient is CC, use the Type property. Change the line

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

to

If recip.Type = 2 Then '2 is olCC

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM