Send email depending on cell values

j844929

Active Member
Joined
Aug 18, 2002
Messages
423
Hi,

I thought I had solved this, but actually, I was nowhere even close...and the entire success of my spreadsheet's effectiveness depends on it....

Does anyone know the code to send an email to a set list of six recipients when cells in a certain column in a worksheet reach a certain value greater than another. Let me explain a little - The action to be performed is date-based.

For Example:

When the date cell L2 is 30 days later than the date in K2, send an email with subject containing data from cells B2 and C3.

However, this has to work for columns K and L in their entirety, as both columns contain a list of dates...

Hope someone can help.

Tim
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Always the same list of email addresses. I've created a mailing list in Outlook already so, ideally, I'd like the mail to be sent to that...
 
Upvote 0
Try this, change the email address, not sure about a mailing list, I've never tried it, let me know if it works;

Code:
Sub Over_30_days_Mail()

'You need to Reference Outlook
'Goto Tools>References and select Microsoft Outlook Libary 9.0 (or your version)
    Dim olApp As Outlook.Application
    Dim olMail As MailItem
    Dim c As Range
    
    For Each c In Range("L2:L" & Range("L65536").End(xlUp).Row)
    
'Do you want to change the formula to > 30
    If c - c.Offset(0, -1) >= 30 Then
    
        Set olApp = New Outlook.Application
        Set olMail = olApp.CreateItem(olMailItem)
                With olMail
'Change email address here **********************************
                    .To = "jim.boy@emailhere.com"
                    .Subject = Range("B" & c.Row).Value & " " & Range("C" & c.Row).Value
'Change name ****************
                    .Body = "Hello" & vbNewLine & vbNewLine & _
                            "Message here"
                    .Send  'Or use Display
                Set olMail = Nothing
        End With
        Set olApp = Nothing
        Application.ScreenUpdating = True
End If
Next c
End Sub
 
Upvote 0
I am forever in your debt. It works like a dream... this is a life-saving device!!!

Tim
 
Upvote 0
j844929 said:
I am forever in your debt. It works like a dream... this is a life-saving device!!!

Tim

Life saving as in a lot of work or life saving as in NHS type thing?
 
Upvote 0
A lot of work...

One thing, actually. I just wondered how to get the script to run every day, whether my workbook is opened or not...?

(In actual fact, it would be an NHS life-saving thing as well, because I've already done the usual and told people that "Yes, or course I can do that!...no problem!!!" - you know the score...)


Tim
 
Upvote 0
I don't know of a way to run it when the workbook isn't opened, try search the board...


You could put a auto_open macro in personal.xls to ask if you want to open the workbook...
 
Upvote 0
Opening the wookrbook is a good idea, because the script runs when the workbook is opened.

How exactly do I do it?
 
Upvote 0
Try this (change the drive and wb name)

Code:
Sub auto_open()
If MsgBox("Do you want to open Book1.xls", vbYesNo) = vbYes Then
Workbooks.Open "C:\Book1.xls"
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,332
Messages
6,124,313
Members
449,153
Latest member
JazzSingerNL

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