问题
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