Hi Friends,
I'm new to VBA and trying to create a macro for sending mails from Outlook using the details in a excel sheet. It works fine. However, I need the code to select the 'From Address' from the excel sheet, but it's not working. PLease help.
Set OutMail = OutApp.CreateItem(0)
strfrom = cell.Offset(0, 2).Value
For Each oAccount In OutApp.Session.Accounts
If oAccount.DisplayName = strfrom Then 'OR oAccount.SmtpAddress = strfrom
With OutMail
.To = cell.Value
.CC = cell.Offset(0, 1).Value
.Subject = cell.Offset(0, 6).Value
.Body = "Hi " & Cells(cell.Row, "B").Value & vbNewLine & vbNewLine & cell.Offset(0, 7).Value & vbNewLine & vbNewLine & cell.Offset(0, 8).Value
strlocation = cell.Offset(0, 9).Value
.Attachments.Add (strlocation)
'Set .sendusingaccount = OutApp.Session.Accounts.Item(cell.Offset(0, 2).Value)
'Set .sendusingaccount = oAccount
'.SentOnBehalfOfName = cell.Offset(0, 2).Value
.Display
.send
End With
End If
Next oAccount
thanks
I'm new to VBA and trying to create a macro for sending mails from Outlook using the details in a excel sheet. It works fine. However, I need the code to select the 'From Address' from the excel sheet, but it's not working. PLease help.
Set OutMail = OutApp.CreateItem(0)
strfrom = cell.Offset(0, 2).Value
For Each oAccount In OutApp.Session.Accounts
If oAccount.DisplayName = strfrom Then 'OR oAccount.SmtpAddress = strfrom
With OutMail
.To = cell.Value
.CC = cell.Offset(0, 1).Value
.Subject = cell.Offset(0, 6).Value
.Body = "Hi " & Cells(cell.Row, "B").Value & vbNewLine & vbNewLine & cell.Offset(0, 7).Value & vbNewLine & vbNewLine & cell.Offset(0, 8).Value
strlocation = cell.Offset(0, 9).Value
.Attachments.Add (strlocation)
'Set .sendusingaccount = OutApp.Session.Accounts.Item(cell.Offset(0, 2).Value)
'Set .sendusingaccount = oAccount
'.SentOnBehalfOfName = cell.Offset(0, 2).Value
.Display
.send
End With
End If
Next oAccount
thanks