I've added a line to this VBA code to add a jpg to the body of this email, but instead, it's added as an attachment. Can this be corrected?
Also, instead of having the contacts folder selected thru the PickFolder, can this be automatic where the VBA code selects the contacts container?
Also, instead of having the contacts folder selected thru the PickFolder, can this be automatic where the VBA code selects the contacts container?
Code:
Public Sub SendDeferredBirthdayGreetings()
Dim bday
Dim objOL As Outlook.Application: Set objOL = Outlook.Application
Dim objFolder As Outlook.MAPIFolder: Set objFolder = Session.PickFolder
'Dim objFolder As Outlook.MAPIFolder: Set objFolder = objOL.ActiveExplorer.CurrentFolder
Dim objItems As Outlook.Items: Set objItems = objFolder.Items
Dim obj As Object
Dim oContact As Object
Dim TheYear As Long
For Each obj In objItems
If TypeName(obj) = "ContactItem" Then
Set oContact = obj
bday = DateSerial(Year(now), Month(oContact.Birthday), Day(oContact.Birthday))
If Month(bday) = Month(Date) Then
If oContact.Email1Address = "" Then GoTo nextrecord
bday = bday + 0.25 ' sets it for 6 am the day of the birthday
Dim objMsg As MailItem: Set objMsg = Application.CreateItem(olMailItem)
objMsg.To = oContact.Email1Address
objMsg.Subject = "Happy Birthday" & " (" & Format(bday, "mmmm dd, yyyy") & ")"
objMsg.Attachments.Add "C:\Users\gailb\Desktop\Happy Birthday.jpg"
objMsg.Body = "Dear " & oContact.FirstName & "," & vbCrLf & vbCrLf & _
"Dropping a not to wish you a Happy Birthday on your special day." & _
vbCrLf & vbCrLf & "Praying you have a great day today and the year ahead is full of an overflowing abundance of blessings." & _
vbCrLf & vbCrLf & "God Bless, Gail"
objMsg.DeferredDeliveryTime = bday
objMsg.Display
' objMsg.Send
Set objMsg = Nothing
End If
End If
nextrecord:
Next
End Sub