Using Excel To Send E-mails

Dazzawm

Well-known Member
Joined
Jan 24, 2011
Messages
3,786
Office Version
  1. 365
Platform
  1. Windows
I have heard you can use excel to send emails. Would it be possible to allocate a number in a cell to an email address then use the data in the cell next to it and add a bit of text that i want run the macro then it sends the e-mail? if it is possible and you need more info please let me know. Thanks.
 
OK, you can hard code the addresses like this

Rich (BB code):
Sub Mail_small_Text_Outlook()
'Working in Office 2000-2010
Dim OutApp As Object
Dim OutMail As Object
Dim strbody As String
Dim LR As Long, i As Long
Dim Addys
Addys = Array("addy1", "addy2", "addy3", "addy4", "addy5", "addy6", "addy7", "addy8", "addy9", "addy10", "addy11")
LR = Range("A" & Rows.Count).End(xlUp).Row


Set OutApp = CreateObject("Outlook.Application")
For i = 1 To LR
    Set OutMail = OutApp.CreateItem(0)
    
    strbody = Range("B" & i).Value & vbNewLine & vbNewLine & "Is in minus?"

    On Error Resume Next
    With OutMail
        .to = Addys(Range("A" & i).Value - 1)
        .CC = ""
        .BCC = ""
        .Subject = "E-mail sent from Excel"
        .Body = strbody
        .Send   'or use .Display
    End With
    On Error GoTo 0
    
    Set OutMail = Nothing
Next i
Set OutApp = Nothing
End Sub
 
Upvote 0

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
So I have to put them in order and it assumes the fourth one I put in would be number 4 and so on?
 
Upvote 0
Thanks just one more thing please. I don't have to have anything in the body of the email just 'data is in minus?' as the subject. Also if I have more than one row with the same number like in my table it will send a separate email for each row?
 
Upvote 0
Try this. It will send an e-mail for each row in column A. It will error if the number in column A is less than 1 or greater than the number of items that you assign to the Addys array.

Code:
Sub Mail_small_Text_Outlook()
'Working in Office 2000-2010
Dim OutApp As Object
Dim OutMail As Object
Dim strbody As String
Dim LR As Long, i As Long
Dim Addys
Addys = Array("addy1", "addy2", "addy3", "addy4", "addy5", "addy6", "addy7", "addy8", "addy9", "addy10", "addy11")
LR = Range("A" & Rows.Count).End(xlUp).Row


Set OutApp = CreateObject("Outlook.Application")
For i = 1 To LR
    Set OutMail = OutApp.CreateItem(0)
    
    strbody = Range("B" & i).Value
    On Error Resume Next
    With OutMail
        .to = Addys(Range("A" & i).Value - 1)
        .CC = ""
        .BCC = ""
        .Subject = "Is in minus?"
        .Body = strbody
        .Send   'or use .Display
    End With
    On Error GoTo 0
    
    Set OutMail = Nothing
Next i
Set OutApp = Nothing
End Sub
 
Upvote 0
Thanks for your time VoG. I will try it Monday when I am at work. I keep finding more questions! If I want more than one e-mail address for a number do I just put a comma next to each one?
 
Upvote 0
I think that you could do it like this. I cannot test as there is a problem with Virgin Media e-mail :(

Code:
Addys = Array("addy1;anotheraddy", "addy2", "addy3", "addy4", "addy5", "addy6", "addy7", "addy8", "addy9", "addy10", "addy11")
 
Upvote 0
I have tried this now and it works ok apart from a couple of small things. Firstly it puts whatever is in 'B' in the body of the e-mail, where I need it to be put in the subject with 'Is In Minus' added to it. Secondly when it goes into the e-mail and is ready for sending it does not put my auto-signature into the e-mail (although this is no biggy). And thirdly where the e-mail addresses are long and go onto a second line in the code they turn red and an error appears? Thanks.
 
Upvote 0
This should fix it

Rich (BB code):
Sub Mail_small_Text_Outlook()
'Working in Office 2000-2010
Dim OutApp As Object
Dim OutMail As Object
Dim strbody As String
Dim LR As Long, i As Long
Dim Addys
Addys = Array("addy1", "addy2", "addy3", "addy4", "addy5", "addy6", _
"addy7", "addy8", "addy9", "addy10", "addy11")
LR = Range("A" & Rows.Count).End(xlUp).Row


Set OutApp = CreateObject("Outlook.Application")
For i = 1 To LR
    Set OutMail = OutApp.CreateItem(0)
    
    strbody = ""
    On Error Resume Next
    With OutMail
        .to = Addys(Range("A" & i).Value - 1)
        .CC = ""
        .BCC = ""
        .Subject = Range("B" & i).Value & "Is in minus?"
        .Body = strbody
        .Send   'or use .Display
    End With
    On Error GoTo 0
    
    Set OutMail = Nothing
Next i
Set OutApp = Nothing
End Sub

Use the _ continuation character to split a line (marked in red).

For the signature see http://www.rondebruin.nl/mail/folder3/signature.htm (probably not worth the effort).
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,711
Members
452,939
Latest member
WCrawford

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