vba - 如何在电子邮件正文中包含发件人的详细信息?
问题描述
我在 MS Word 中有一个宏:
- 单击按钮即可创建 Outlook 电子邮件
- 将 Word 文档附加到 Outlook 电子邮件
我想在电子邮件正文中包含发件人的详细信息(姓名、电子邮件地址等)。
Dim Outlook_Object As Object
Dim Email_Object As Object
Dim This_document As Document
Application.ScreenUpdating = False
Set Outlook_Object = CreateObject("Outlook.Application")
Set Email_Object = Outlook_Object.CreateItem(olMailItem)
Set This_document = ActiveDocument
This_document.Save
With Email_Object
.Subject = "REPORT REQUEST FORM"
.Body = "This is a test email."
.To = "john.smith@gmail.com"
.Importance = olImportanceNormal
.Attachments.Add This_document.FullName
.Display
End With
Set This_document = Nothing
Set Email_Object = Nothing
Set Outlook_Object = Nothing
Application.ScreenUpdating = True
解决方案
您可以使用NameSpace.CurrentUser属性,该属性将当前登录用户的显示名称作为Recipient
对象返回。Recipient.AddressEntry属性返回AddressEntry
对应于已解析收件人的对象。然后你可以得到Name
和Address
属性,如下所示:
Dim ns as Outlook.NameSpace
Set ns = OutlookApplication.GetNamespace("MAPI")
' to get the email address of the sender
ns.CurrentUser.AddressEntry.Address
' to get the name
ns.CurrentUser.AddressEntry.Name
要将此信息包含到消息正文中,您可以使用Body
或HTMLBody
属性。
推荐阅读
- swift - 使用 NVActivityIndicatorView 和 Timer,它显示的时间很短
- javascript - 来自 mongodb 查找查询的空白结果
- python - 我们可以使用 argcomplete 来完成 bash tab 完成而不在 shell 中编写 python 关键字吗?
- r - paste 如何在函数中工作
- java - 无法在 Oracle 中使用 dbms_java.loadjava 加载 jar
- r - 从列表列表中读入文件
- swift - 在 SwiftUI 中显示小吃店消息
- javascript - 渲染在使用状态时无法在反应 js 中工作
- python - 在 python 中开发时,如何在 post 请求中使用“format=json&data=”?
- firebase - 如何将 firebase 托管和 firebase 功能连接到不同的域