Forum

Send email when exc...
 
Notifications
Clear all

Send email when excel opens and it recognises a cell date is due to expire

2 Posts
2 Users
0 Reactions
79 Views
(@barlow81)
Posts: 1
New Member
Topic starter
 

Hello!

I have written the below so I can send the excel as an attachment. Is there a way to only create the email when a date is due to expire. Column E = Email Date (in month-year)

Sub Certificate_Renewal_Programme()

'Step 1: Declare our variables
Dim OLApp As Outlook.Application
Dim OLMail As Object

'Step 2: Open Outlook start a new mail item
Set OLApp = New Outlook.Application
Set OLMail = OLApp.CreateItem(0)
OLApp.Session.Logon

'Step 3: Build our mail item and send
With OLMail
.To = "[email protected]; [email protected]"
.CC = "[email protected]"
.Subject = "Certification Renewal Programme"
.Body = "Please see attached and action and items highlighted in red. Please advise Quality once complete so they can change the document accordingly."
.Attachments.Add ActiveWorkbook.FullName
.Display
End With

'Step 4: Memory cleanup
Set OLMail = Nothing
Set OLApp = Nothing

End Sub

 

Thank you.

 
Posted : 22/06/2021 9:51 am
(@catalinb)
Posts: 1937
Member Admin
 

Hi Rachel,

What expire means for you?

The cell date reaches today's date, or is a few days before current date?

You can play with the below code, placed in ThisWorkbook module:

Private Sub Workbook_Open()
If CLng(ActiveSheet.Cells(2, "E").Value) >= CLng(Date) Then Certificate_Renewal_Programme
End Sub

 
Posted : 26/06/2021 12:11 am
Share: