Hi Everyone,
i have written macro to send mail on every friday and on last date of every month. But when i run the mcaro i am getting error. subject line in the mail should change according to the weeks (eg: for this week suject should be enter eforts from 03/17/2014 to 03/19/2014).I have another doubt , can we able to attach a screenshot in the body of the mail.Please help me.
Public Sub Mail_small_Text_Outlook()
Dim OutApp As Object
Dim OutMail As Object
Dim strbody As String
Dim dat As Date, y As Date, z As Date
Dim str As String, abc As String
str = WeekdayName(Weekday(Now()))
dat = Date
y = dat - 7
z = Application.WorksheetFunction.EoMonth(dat, 0)
abc = "Today is not friday or month end. So i cannot send the mail"
If (str = friday) Then
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
strbody = "Hi All" & vbNewLine & vbNewLine & _
"Please enter your efforts for the period of (" y "to" dat ")before Today EOD" & vbNewLine & _
"<B> Note: </B>" & vbNewLine & _
"Please remember to create tasks with Phase, Activity and Task mapping" & vbNewLine & _
'Above line should be displayed in red
"Make sure that you have chosen Guardian as your C2.0 project before entering your efforts"& vbNewLine & _
'Above line should be displayed in red
"<B>Planned hours for any task cannot exceed 45hrs</B>"& vbNewLine & _
'Above line should be displayed in red
"This is line 4"& vbNewLine & _
On Error Resume Next
With OutMail
.To = "xxxx@company.com"
.CC = ""
.BCC = ""
.Subject = "Enter the efforts for the period (03/17/2014 to 03/21/2014)"
'In the above subject line period should change according to the week can we able to write like that
.Body = strbody
'You can add a file like this
'.Attachments.Add ("C:\test.txt")
.Send 'or use .Display
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
Else
If (dat = z) Then
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
strbody = "Hi All" & vbNewLine & vbNewLine & _
"Please enter your efforts for the whole month" & vbNewLine & _
"<B> Note: </B>" & vbNewLine & _
"Please remember to create tasks with Phase, Activity and Task mapping" & vbNewLine & _
'Above line should be displayed in red
"Make sure that you have chosen Guardian as your C2.0 project before entering your efforts"& vbNewLine & _
'Above line should be displayed in red
"<B>Planned hours for any task cannot exceed 45hrs</B>"& vbNewLine & _
'Above line should be displayed in red
"This is line 4"& vbNewLine & _
On Error Resume Next
With OutMail
.To = "xxxx@company.com"
.CC = ""
.BCC = ""
.Subject = "Enter the efforts for the period (03/1/2014 to 03/31/2014)"
'In the above subject line period should change according to the week can we able to write like that
.Body = strbody
'You can add a file like this
'.Attachments.Add ("C:\test.txt")
.Send 'or use .Display
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
Else
MsgBox abc
End Sub
Bookmarks