using other mail account by sending mail from Excel to outlook [duplicate]

巧了我就是萌 提交于 2021-01-29 08:05:41

问题


I have this macro running in VBA. it is to send a mail out of Excel using Outlook. Now i have two accounts on outlook, let's say Test1@outlook.com and Test2@outlook.com

Outlook is automatically using test1@outlook.com, but i want it to use Test2@outlook.com when i use this macro. Can anybody help my?

Dim xOutApp As Object
    Dim xOutMail As Object
    Dim xMailBody As String
    On Error Resume Next
    Set xOutApp = CreateObject("Outlook.Application")
    Set xOutMail = xOutApp.CreateItem(0)
    xMailBody = "Hello," & vbNewLine & vbNewLine & _
              "Please find attached our forms" & vbNewLine & _
              "" & vbNewLine & _
              "Have a nice day!" & vbNewLine & _
               "" & vbNewLine & _
                "" & vbNewLine & _
              ""
                  On Error Resume Next
    With xOutMail
        .To = "leroy@driesen.nl"
        .CC = ""
        .BCC = ""
        .Subject = " /  " + Format(Range("B2 ")) + " / " + Format(Range("C2")) + " / " + Format(Range("D2")) + " / " + Format(Range("E2")) + " / " + Format(Range("F2")) + " / Job nr. " + Format(Range("G2"))
        .Body = xMailBody
        .Display   'or use .Send
    End With
    On Error GoTo 0
    Set xOutMail = Nothing
    Set xOutApp = Nothing
End Sub

Many thanks!

来源:https://stackoverflow.com/questions/64264085/using-other-mail-account-by-sending-mail-from-excel-to-outlook

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!