=TODAY()
=IF(AND(MONTH(B4)=MONTH(nrToday),DAY(B4)=DAY(nrToday)),"Anniversary","")
=DATEDIF([@Hired],nrToday,"Y")
Option Explicit
Private Sub Workbook_Open()
Dim rngCell As Range
Dim strMessage As String
For Each rngCell In Range("tblX[Name]")
If rngCell.Offset(0, 3) = "Anniversary" Then
strMessage = "Congratulations, yo!<br><br>" & _
"We are so totally chuffed to have " & _
"you working with us.<br><br>Happy " & _
Addth(rngCell.Offset(0, 4).Value) & _
" Work Anniversary!"
Call Email _
(rngCell.Offset(0, 2), "Happy Anniversary!", strMessage)
strMessage = ""
End If
Next rngCell
End Sub
Option Explicit
Function Addth(pNumber As String) As String
'Updateby20141027
'Function Posted At:
'https://www.extendoffice.com/documents/excel/2167-excel-convert-cardinal-to-ordinal.html
Select Case CLng(VBA.Right(pNumber, 1))
Case 1: Addth = pNumber & "st"
Case 2: Addth = pNumber & "nd"
Case 3: Addth = pNumber & "rd"
Case Else: Addth = pNumber & "th"
End Select
Select Case VBA.CLng(VBA.Right(pNumber, 2))
Case 11, 12, 13: Addth = pNumber & "th"
End Select
End Function
Sub Email _
(sTo As String, sSub As String, _
sHTML As String, Optional sAttach As Variant, _
Optional sAction As String = "Display", _
Optional sCCs As String, Optional sSender As String)
'v1.49 31 Mar 2023
'https://www.RONDEBRUIN.nl/win/s1/outlook/signature.htm
'with appreciation to ChatGPT for help with the attachment
'logic
'Declare Variables
Dim lngLoop As Long
Dim olApp As Object
Dim olMsg As Object
Dim arrEh As Variant
'Create Email Message
Set olApp = CreateObject("Outlook.Application")
Set olMsg = olApp.CreateItem(0)
On Error Resume Next
Set olApp = GetObject(, "Outlook.Application")
If olApp Is Nothing Then _
Set olApp = CreateObject("Outlook.Application")
Set olMsg = olApp.CreateItem(0)
With olMsg
.Display
If sSender <> "" Then
.SentOnBehalfOfName = sSender
End If
.To = sTo
.CC = sCCs
.HTMLBody = sHTML & .HTMLBody
.Subject = sSub
If Not IsMissing(sAttach) And Not IsNull(sAttach) Then
If Not IsArray(sAttach) Then
.Attachments.Add sAttach
GoTo Utah
End If
For lngLoop = LBound(sAttach) To UBound(sAttach)
.Attachments.Add sAttach(lngLoop)
Next lngLoop
Utah:
End If
If sAction = "Display" Then
.Display
ElseIf sAction = "Send" Then
.Send
End If
End With
On Error GoTo 0
'Clear Set Variables
Set olApp = Nothing
Set olMsg = Nothing
End Sub
=IF(AND(MONTH(B4)=MONTH(nrToday),DAY(B4)=DAY(nrToday)),"Birthday person!","")
Private Sub Workbook_Open()
Dim rngCell As Range
For Each rngCell In Range("tblPeeps[Name]")
If rngCell.Offset(0, 3) = "Birthday person!" Then
Call Email _
(rngCell.Offset(0, 2), "Happy Birthday!", "For you're a jolly good fellow, folderol lorem ipsum!")
End If
Next rngCell
End Sub
Sub Email _
(sTo As String, sSub As String, _
sHTML As String, Optional sAttach As Variant, _
Optional sAction As String = "Display", _
Optional sCCs As String, Optional sSender As String)
'v1.49 31 Mar 2023
'Crafted by Ron DeBruin, Wookiee at MrExcel, and ChatGPT
'https://www.RONDEBRUIN.nl/win/s1/outlook/signature.htm
'Declare Variables
Dim lngLoop As Long
Dim olApp As Object
Dim olMsg As Object
Dim arrEh As Variant
'Create Email Message
Set olApp = CreateObject("Outlook.Application")
Set olMsg = olApp.CreateItem(0)
On Error Resume Next
Set olApp = GetObject(, "Outlook.Application")
If olApp Is Nothing Then _
Set olApp = CreateObject("Outlook.Application")
Set olMsg = olApp.CreateItem(0)
With olMsg
.Display
If sSender <> "" Then
.SentOnBehalfOfName = sSender
End If
.To = sTo
.CC = sCCs
.HTMLBody = sHTML & .HTMLBody
.Subject = sSub
If Not IsMissing(sAttach) And Not IsNull(sAttach) Then
If Not IsArray(sAttach) Then
.Attachments.Add sAttach
GoTo Utah
End If
For lngLoop = LBound(sAttach) To UBound(sAttach)
.Attachments.Add sAttach(lngLoop)
Next lngLoop
Utah:
End If
If sAction = "Display" Then
.Display
ElseIf sAction = "Send" Then
.Send
End If
End With
On Error GoTo 0
'Clear Set Variables
Set olApp = Nothing
Set olMsg = Nothing
End Sub
I re-read my message and it occurred to me that I failed to mention that the Workbook_Open macro needs to be put in the worksheet itself, not the code module. I hope that helps.hello thanks
i did one with instruction but its not working so far
will continue to test
Thanks
To be clear, it needs to go in the "ThisWorkbook" module, not any of the Sheet modules or in any General module that you insert.I re-read my message and it occurred to me that I failed to mention that the Workbook_Open macro needs to be put in the worksheet itself, not the code module. I hope that helps.