首页 > 解决方案 > 从 Outlook 会议项目复制收件人姓名

问题描述

我有一个打开的 Outlook 会议项目。

我会手动输入收件人的姓名并运行一个宏,将收件人复制到剪贴板。

这是一个屏幕截图,其中有两个收件人。该宏应将两个名称复制到剪贴板中。
在此处输入图像描述

我的代码复制整个代码而不是收件人姓名。

Sub cellSel()

    Dim clipboard As MSForms.DataObject
    Dim str1 As String
    Dim objWSS

    Set objWSS = CreateObject("WScript.Shell")
    objWSS.SendKeys "^a"
    objWSS.SendKeys "^c"
    Set clipboard = New MSForms.DataObject
    clipboard.GetFromClipboard

    If TypeName(ActiveWindow) = "Inspector" Then
        If ActiveInspector.IsWordMail And ActiveInspector.EditorType = olEditorWord Then
            MsgBox (clipboard.GetText)
            With ActiveInspector.WordEditor.Application.ActiveDocument
                With .Tables(1)
                    '.Cell(2, 2).Range.Select
                    .Cell(2, 3).Range.Text = clipboard.GetText
                    '.Cell(3, 2).Range.Text = clipboard.GetText
                End With
            End With
        End If
    End If
End Sub

标签: vbaoutlook

解决方案


使用Recipients属性获取收件人姓名。该属性返回Recipients代表 Outlook 项目的所有收件人的集合。

使用Recipients (index)(其中index是名称或索引号)返回单个 Recipient 对象。名称可以是表示显示名称、别名或收件人的完整 SMTP 电子邮件地址的字符串。

Sub DemoMeetingRecipients() 
 Dim myAppointment As Outlook.AppointmentItem 
 Dim myPA As Outlook.PropertyAccessor 
 Dim d As Long 
 Dim myInt As Long 

 Set myAppointment = Application.ActiveInspector.CurrentItem 

 For d = 1 To myAppointment.Recipients.count 
 Debug.Print myAppointment.Recipients.item(d).name 
 Debug.Print myAppointment.Recipients.item(d).Type 
 Set myPA = myAppointment.Recipients.item(d).PropertyAccessor 
 myInt = myPA.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x39050003") 
 Debug.Print myInt 
 Debug.Print "---" 
 Next d 
End Sub

推荐阅读