Dim OutApp As Object
Dim OutMail As Object
Dim EmailTo As String
Dim EmailCC As String
Dim EmailSub As String
Dim EmailBody As String
Dim EmailFrom As String
vFilePath = Range("rFilePath").Value
EmailFrom = Range("EmailFrom").Value
' EmailTo = Range("Email_List").Value
' EmailCC = Range("EmailCC").Value
EmailSub = Range("EmailSub").Value
' EmailBody = Range("EmailBody").Value
Set OutApp = CreateObject("Outlook.Application")
Set OutNS = OutApp.GetNamespace("MAPI")
OutNS.Logon
'OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
'.From = EmailFrom
Dim accounts As Outlook.accounts
Dim Account As Outlook.Account
Dim MyAccount As Outlook.Account
Set accounts = OutNS.accounts
.To = EmailTo
.CC = EmailCC
.BCC = ""
.Subject = EmailSub
.Body = EmailBody
.Attachments.Add ActiveWorkbook.FullName
' Loop over the Accounts collection of the current Outlook session.
For Each Account In accounts
' When the e-mail address matches, return the account.
If Account.SmtpAddress = EmailFrom Then
' Use this account to send the e-mail.
Set MyAccount = Account
End If
Next
Set .SendUsingAccount = MyAccount
' If xfile = 1 Then
' .Attachments.Add ("S:\Path\To\Attachment")
' End If
' On Error GoTo 0
.Display
'.Send
Set OutMail = Nothing
Set MyAccount = Nothing
Set accounts = Nothing
Set OutNS = Nothing
Set OutApp = Nothing