Sending an email via VBA

Anthony86

Board Regular
Joined
Jan 31, 2018
Messages
70
Office Version
  1. 365
Platform
  1. Windows
Hi All,

I'm using some code from the net that sends an email if the due date is close but what I want it to do is if the name in column "F" is the same then send multiple lines in one email, if its different then send a separate email.

Is this possible?

This is the code that I'm using

VBA Code:
Dim Email As String, Subj As String
    Dim Msg As String
    Dim LastRow As Long, NextRow As Long, RowNo As Long
    Dim wsEmail As Worksheet
    Dim OutApp As Object
    Dim OutMail As Object

    Set wsEmail = ThisWorkbook.Sheets("SheetName")
    
    With wsEmail
        LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row

        For RowNo = 2 To LastRow
            'Change "Date + 30" to suit your timescale
            
            If .Cells(RowNo, "K") = "" And .Cells(RowNo, "E") <= Date + 7 Then
                
                On Error Resume Next
                Set OutApp = GetObject("Outlook.Application")
                    On Error GoTo 0
                    If OutApp Is Nothing Then Set OutApp = CreateObject("Outlook.Application")
                    Do: Loop Until Not OutApp Is Nothing
                Set OutMail = OutApp.CreateItem(0)
                With OutMail
                    Email = "User@email.com" 'Change to cell containing e-mail address
                    Subj = "Reminder for Destruction" 'Change to cell containing subject or type subject
                    'Msg = ""
                    
                    Msg = "Hello" & "," & vbCrLf & vbCrLf _
                        & "This is an automated e-mail to let you know that box" & vbCrLf _
                        & wsEmail.Cells(RowNo, "A") & vbCrLf _
                        & "Is due for destruction on " & wsEmail.Cells(RowNo, "E") & vbCrLf _
                        & "Many Thanks, " & vbCrLf
                        
                    .To = Email
                    .CC = ""
                    .SentOnBehalfOfName = "Your User Name" ' This is optional, you can delete this line.
                    .Subject = Subj
                    .ReadReceiptRequested = False
                    .Body = Msg
                    .Display

                End With
            Set OutApp = Nothing
            Set OutMail = Nothing
            .Cells(RowNo, "K") = "S"
            .Cells(RowNo, "L") = "E-mail sent on: " & Now()
        End If
        Next
    End With
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Hi, not sure if this is possible but can an email be sent only if the criteria matches. Criteria for this is below..

1)Sheet1 Column E has an email address
2)Sheet1 Column G is blank (This will be populated once an email is sent

3)Match the value from worksheet 1 column C to worksheet 2 Column A. Then use the data in worksheet 2 Column B and append to the email

I'm sending alot of emails out and the same text goes out to them if they fall within a certain group, rather than me doing this manually I was wondering if vba can achieve this?
Worksheet 2 has all the group names in column A and column B has all the text that I need to send out. Worksheet 1 has all the people/email address that I need to send to, this list can change daily which is why I was hoping vba can help.

Really appreciate your help
 
Upvote 0
It seems to me a completely new requirement.
You could create a new thread.
In the thread, explain with examples, several examples, without examples it is very difficult to understand what you need.
Then with examples, very well explained, with images or with ranges of cells.
It is also important that you put how you want the final result. The final result also in an image, the final result should be the data you put in the previous examples.

Upload an excel range:
XL2BB - Excel Range to BBCode
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

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