首页 > 解决方案 > 打开电子邮件附件文件

问题描述

我使用以下代码打开附件文件

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

电子邮件附件文件未打开。

如何在宏中打开电子邮件附件文件?

标签: excelvbaoutlook

解决方案


Excel 对象模型中的Application类不提供该User属性。相反,您可以使用UserName返回当前用户名称的属性。

MsgBox "Current user is " & Application.UserName

该属性返回或设置Outlook 项目收件人MailItem.To的显示名称的分号分隔字符串列表。To但我建议使用应该用于修改属性的Recipients集合。To


推荐阅读