Sub SendEmailOnOpen()
Dim ws As Worksheet
Dim cell As Range
Dim emailSent As Boolean
Dim emailAddress As String
Dim emailSubject As String
Dim emailBody As String
Dim textList As String
emailAddress = "abc@mail.com"
emailSubject = "Alert: License Renewal"
emailBody = "One or more licenses are within 30 days or less and require renewal:" & vbNewLine & vbNewLine
textList = ""
Set ws = ThisWorkbook.Sheets("License tracker")
emailSent = False
For Each cell In ws.Range("L2:L52")
If cell.Value > 0 And cell.Value < 30 Then
textList = textList & "- " & ws.Cells(cell.Row, 1).Value & vbNewLine
emailSent = True
End If
Next cell
If emailSent Then
emailBody = emailBody & textList
With CreateObject("Outlook.Application").CreateItem(0)
.To = emailAddress
.Subject = emailSubject
.Body = emailBody
.Send
End With
End If
End Sub