vba - 从 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
解决方案
使用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
推荐阅读
- mysql - 如何将转换后的行汇总并集中到一个具有相同 ID 的字段中?
- python - Selenium 网络请求 - 查找或计算网络请求文件的 URL
- python - 函数无法识别导入的包
- sql - 计算退出日期和退出日期前 3 个月之间的工作时间 bigquery sql
- python - 如何删除标记滑块中幅度初始值的小红线?
- sql - 从 mysql 工作台导入数据
- javascript - 将 if/else 语句转换为三元运算符
- linux - 在 Linux 终端中抑制 & 的输出
- python - 使用最新版本的 Pandas 读取 excel 时出现问题
- python - MacOS Big Sur 编辑此文件夹中的图像:System/Library/Desktop Pictures/Big Sur Graphic.heic