excel - 打开电子邮件附件文件
问题描述
我使用以下代码打开附件文件
Sub Test()
Dim path As String
Dim msgFile As String
path = Application.ActiveWorkbook.path + "\"
file = path & "\*.msg"
Dim OutApp As Outlook.Application
Dim OutMail As Outlook.mailitem
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItemFromTemplate(file)
On Error Resume Next
With OutMail
.To = Application.User
.Send
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
但
电子邮件附件文件未打开。
如何在宏中打开电子邮件附件文件?
解决方案
Excel 对象模型中的Application
类不提供该User
属性。相反,您可以使用UserName
返回当前用户名称的属性。
MsgBox "Current user is " & Application.UserName
该属性返回或设置Outlook 项目收件人MailItem.To
的显示名称的分号分隔字符串列表。To
但我建议使用应该用于修改属性的Recipients集合。To
推荐阅读
- kubernetes - Kubeflow jupyter notebook 已创建,但没有 notebook 资源
- c++ - c ++模板特化与派生类
- azure-devops - Azure Pipeline 中的 Snyk 安全扫描任务
- apache-kafka - 在 Google Cloud Run 上运行 Kafka 消费者
- macos - 如何在终端上找到每天发送的电子邮件数量
- laravel - 如何从 Laravel 调用 MongoDB 存储函数。(Mongo 版本 4.2.2)
- ios - 当我推送视图控制器时标签不显示
- javascript - 具有预定义项目和未知项目的递归接口
- python - 为具有包含特定文本的子元素的特定类选择一个 div
- file-upload - 上传到 Dropbox 的图片没有任何内容