如何使用Excel VBA打开msg文件并编辑接收器?

时间:2018-04-11 16:01:15

标签: excel-vba outlook vba excel

如何打开保存为.msg文件的Outlook mailitem,使用Excel VBA编辑和发送?

我知道有很多代码缺失,但我尝试了许多开放方法但没有成功。

我必须使用.msg文件。

Private Sub CommandButton22_Click()

    'Send msg

    Dim path As String
    Dim msgFile As String

    path = Application.ActiveWorkbook.path + "\"

    file = path & "test.msg"

    'here I want to edit the receiver(To) of the msg File then send it
    'but I don't know how

    Dim outApp As Object
    Dim OutMail As Object
    Set outApp = CreateObject("Outlook.Application")
    Set OutMail = outApp.CreateItem(0)

    With OutMail
        .To = "someone@whatever.com"
        .Send
    End With

End Sub

2 个答案:

答案 0 :(得分:0)

使用{{1}}。

答案 1 :(得分:0)

我找到了解决方案

'Send msg

Dim path As String
Dim msgFile As String

path = Application.ActiveWorkbook.path + "\"

file = path & "test.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