【发布时间】:2020-09-21 09:01:59
【问题描述】:
我想将 word 文档的正文作为电子邮件发送,但我希望用户能够使用通讯簿从 MS Word 2016 中选择要将其发送给哪些收件人。当用户选择要发送的电子邮件时到,我希望他们只能输入密件抄送字段。
我卡住的地方是监视 to/from/CC/BCC 字段的更改,然后将这些更改移动到 BCC。该文档似乎表明了 Inspectors 的使用,但没有具体说明访问这些字段的内容。
对此我有两种方法,一种是打开一个新的 Outlook 邮件项目,将 word 文件的内容加载到其中,然后尝试以这种方式监视字段。
另一种方法是使用快速访问工具栏选项“发送给邮件收件人”直接从 word 发送,打开一封电子邮件,然后以这种方式发送。但我不知道根据我所阅读的内容,这是否真的是一个选项,以及这些字段是否可以通过 VBA 访问。
到目前为止我所拥有的代码示例如下:
Dim bStarted As Boolean
Dim oOutlookApp As Outlook.Application
Dim oItem As Outlook.MailItem
On Error Resume Next
'Get Outlook if it's running
Set oOutlookApp = GetObject(, "Outlook.Application")
If Err <> 0 Then
'Outlook wasn't running, start it from code
Set oOutlookApp = CreateObject("Outlook.Application")
bStarted = True
End If
'Create a new mailitem
Set oItem = oOutlookApp.CreateItem(olMailItem)
With oItem
'Set the recipient for the new email
.To = "recipient@mail.com"
'Set the recipient for a copy
.CC = "recipient2@mail.com"
'Set the subject
.Subject = "New subject"
'The content of the document is used as the body for the email
.Body = ActiveDocument.Content
.Send
End With
If bStarted Then
'If we started Outlook from code, then close it
oOutlookApp.Quit
End If
'Clean up
Set oItem = Nothing
Set oOutlookApp = Nothing
End Sub
【问题讨论】: