- In your workbook hit Alt + F11 to open the VBA editor.
- Find your workbook's name in the VBAProject window on the left
- Right click --> Insert --> Module
- You can rename the module if you like
- Double click on the newly created module
- Paste the following code into it
Option Explicit
Sub EmailNoReplys()
Dim sSubject As String, sBody As String, sTo As String, sDomain As String
Dim r As Integer
Dim ThisWB As Workbook, ThisWS As Worksheet
Set ThisWB = ThisWorkbook
Set ThisWS = ThisWB.Worksheets("Sheet1") 'Change this
sSubject = "Subject" 'Change to suit
sBody = "Body" 'Change to suit
sDomain = "@domain.com" 'Change to suit
r = 2
With ThisWS
Do Until Trim(Cells(r, 1).Value) = ""
If .Cells(r, 3) = "None" Then 'if Response is 'None' will need to be exactly that...not 'none' or 'none ' or 'None ' etc...
'Build the 'To' list
If sTo = "" Then
sTo = .Cells(r, 1).Value & sDomain & "; "
Else
sTo = sTo & .Cells(r, 1).Value & sDomain & "; "
End If
End If
r = r + 1
Loop
End With
EMail sTo, sSubject, sBody, False 'Change last argument to true if you want it to send right away
End Sub
Function EMail(StrTo As String, _
StrSubject As String, StrBody As String, Send As Boolean)
Dim OutApp As Object
Dim OutMail As Object
Dim signature As String
On Error Resume Next
Set OutApp = GetObject(, "Outlook.Application")
If Err.Number <> 0 Then
Err.Clear
Set OutApp = CreateObject("Outlook.Application")
End If
Set OutMail = OutApp.CreateItem(0)
Application.ScreenUpdating = False
With OutMail
.Display
End With
signature = OutMail.HTMLBody
Application.ScreenUpdating = True
On Error GoTo ExitFunc
With OutMail
.To = StrTo
.cc = ""
.BCC = ""
.Subject = StrSubject
.HTMLBody = StrBody & "<br>" & signature
If Send = True Then
.Send
Else
.Display
End If
End With
ExitFunc:
Set OutMail = Nothing
Set OutApp = Nothing
End Function
Edit the items in the code marked "Change" or "Change to suit"!
Now to add a button to your sheet to execute the code!
In Office 2010 or 2013 follow these steps to add the Developer Tab if you don't have it- Click on File
- Click on Options
- Click on Customize Ribbon
- Check "Developer" in the list on the right
- Click OK
Back in your sheet...- Click on the Developer Tab
- Click on Insert
- From the drop down select the top leftmost icon ... Button Form control
- It will create a cross hairs for you to draw the button where you want it
- After drawing the button a dialog will pop up for you to select the macro you want executed when the button is clicked
- Select your new macro's module name
Bookmarks