Hi, Mukesh,
there is no reference for Outlook set in the sample Workbook. You would need to set that, then try the code again and you will receive another error.
You should really take some of the basics of writing/working on code. As you are pretty new to VBA I strongly recommend to put each command on a line of it´s own instead of using multiple commands in one line. And you should work with proper indention on the code so that you should have noted that there is an End If missing. Further on you don´t have a sheet Personal in the workbook.
pRow isn´t dimmed nor initialized so it holds a value of 0 and will cause another error - a very strong argument to work with Option Explicit..
Sub memberbirthday()
Dim x, i&, cnt&, OutApp As Outlook.Application
Dim Msg1 As String, Msg2 As String, Msg3 As String, Msg4 As String, Msg5 As String
Dim Msg6 As String, Msg7 As String, Msg8 As String, Msg9 As String, Msg10 As String
Dim Msg11 As String, Msg12 As String, msg13 As String
With Sheets("Sheet1")
x = .Range("o8:Z" & .Cells(Rows.Count, "p").End(xlUp).Row + 1).Value
End With
For i = 1 To UBound(x)
If IsDate(x(i, 2)) Then
If Cells(7 + i, 32).Value <> "Send mail" Then
If Month(x(i, 2)) = Month(Date) And Day(x(i, 2)) = Day(Date) Then
If Len(x(i, 8)) > 2 Then
MsgBox x(i, 1) & "'s Birthday Today!", 64
' Create Outlook object
Set OutApp = New Outlook.Application
Msg1 = "WISH YOU HAPPY BIRTHDAY!": Msg2 = "Dear " & x(i, 1) & ",": Msg3 = """Hope your Special day": Msg4 = "Brings you all that"
Msg5 = "Your heart desires": Msg6 = "Here's wishing you a day": Msg7 = "Full of pleasant surprises!": Msg8 = "Happy Birthday"""
Msg9 = "I have a great pleasure to convey my best wishes on the occasion of your Birth Day!"
Msg10 = """May God offer you a very Healthy and Wealthy life ahead!!"""
Msg11 = "With regards,": Msg12 = "Mukesh Baviskar": msg13 = "Mobile: 1234554321"
'Create Mail Item and view before sending
With OutApp.CreateItem(olMailItem)
.To = x(i, 8) 'EmailAddr
.Subject = "Happy Birthday"
'.HTMLBody = "<center><img src='C:\Cake.jpg'></center><br><br>" 'Insert the full windows path of your image here
'.HTMLBody = .HTMLBody & "<font color='red'>"
.HTMLBody = "<html>" & "<center><b><i><font face=""Comic Sans MS"" size=""3"" color=""red"">" & Msg1 & "</font></i></b></center><br/><br/>" & _
"<center><img src='C:\Cake.jpg'></center><br><br>" & _
"<center><b><font face=""Comic Sans MS"" size=""2"" color=""green"">" & Format(Date, "dd mmmm yyyy") & "</font></b></center><br/><br/>" & _
"<font face=""Comic Sans MS"" size=""2"" color=""FF1CAE"">" & Msg2 & _
"<center><b><font face=""Comic Sans MS"" size=""2"" color=""blue""><br/><br/>" & _
Msg3 & "<br>" & Msg4 & "<br>" & Msg5 & "<br>" & Msg6 & "<br>" & Msg7 & "<br>" & Msg8 & _
"</font></b></center><br><br><font color='FF1CAE'>" & Msg9 & "<br><br>" & Msg10 & "<br><br>" & _
"<font face=""Comic Sans MS"" size=""2"" color=""red"">" & Msg11 & "<br><br>" & Msg12 & "<br><br>" & msg13 & "</font>"
'.Attachments.Add ("c://Happy Birthday.xlsm") ' for example
.Display: .Send
End With
Set OutApp = Nothing: cnt = cnt + 1
'------------------- End Creating Email using outlook ---------------
Else
MsgBox x(i, 1) & "'s Birthday Today! & has empty E-mail address", 48
End If 'If Len(x(i, 8)) > 2 Then
End If
End If
End If
Next i
Msg1 = "The task completed successfully!": MsgBox Msg1, 64
End Sub
Mostly I wonder why you get code in your earlier threads that works and decide to sort of shredder these codes so they don´t work and then come back for help.
Ciao,
Holger
Bookmarks