Hi,
I have been working on your code now for a while. I am sorry If I modified it too much. Right now the creating part of the emails is clean and ready to lunch. This is how the code looks like
Public Const Msg3 As String = """Hope your Special day"
Public Const Msg4 As String = "Brings you all that"
Public Const Msg5 As String = "Your heart desires"
Public Const Msg6 As String = "Here's wishing you a day"
Public Const Msg7 As String = "Full of pleasant surprises!"
Public Const Msg10 As String = """May God offer you a very Healthy and Wealthy life ahead!!"""
Public Const Msg11 As String = "Please see the attachment."
Public Const Msg12 As String = "With regards,"
Public Const Msg13 As String = "Mukesh Baviskar"
Sub Mail_1A(EmailAddr As String, Name As String)
' Basecode can be found http://msdn.microsoft.com/en-us/library/office/ff458119(v=office.11).aspx
' Works in Excel 2000, Excel 2002, Excel 2003, Excel 2007, Excel 2010, Outlook 2000, Outlook 2002, Outlook 2003, Outlook 2007, Outlook 2010.
' This example sends the last saved version of the Activeworkbook object .
Dim OutApp As Object
Dim OutMail As Object
'variables for the body and recepients
Dim cell As Range
Dim Subj As String
Dim Recipient As String
Dim Msg1, Msg2, Msg8, Msg9 As String
'add values to the known variables
Subj = "Happy Birthday"
Msg1 = "WISH YOU HAPPY BIRTHDAY!"
Msg2 = "Dear " & Name & ","
Msg8 = "Happy Birthday"""
Msg9 = "I have a great pleasure to convey my best wishes on the occasion of your Birth Day!"
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
' Change the mail address and subject in the macro before you run it.
With OutMail
.To = EmailAddr
.Subject = Subj
.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>" & _
Msg11 & "<br><br>" & "<font face=""Comic Sans MS"" size=""2"" color=""red"">" & Msg12 & _
"<br><br>" & Msg13 & "</font>"
' In place of the following statement, you can use ".Display" to
.Display
'.Send
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
Sub try()
Call Mail_1A("Al@ya.com", "Afredo")
End Sub
The last small code is just me debugging it and testing.
There note that the code has some arguments that will be passed once its in the conditional code of the Workbook_open.
There is something I don't understand every time you send an email you Fill the cells with Yellow ?
Thanks
PS: I have mail 1 through 4 but I cannot post such a big text here.
Bookmarks