Select 'From Address' in Outlook

ankit4u4

New Member
Joined
Aug 18, 2017
Messages
1
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
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.

Forum statistics

Threads
1,216,175
Messages
6,129,299
Members
449,499
Latest member
HockeyBoi

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top