On 2002-09-16 02:57, Andrew Poulsom wrote:
Unfortunately SendMail does not have a Body argument, so you will need to use Outlook VBA.
See this link:
http://www.mrexcel.com/board/viewtopic.php?topic=20793&forum=2
First of all thanks to Dennis and Andrew for their prompt responses.
Guys, the following code is working with a little problem that it sends every user two emails, one with attachement and one with a blank message in body text. I have checked the attachment is fine with a INCOMING DATE of only the intended employee (controlled through an array variable and a loop).
I am quite sure, I will also get a hold of it with God's help.
Sub post()
Dim objOutlook
Dim objNameSpace
'
Dim mItem
Dim strReceipient
Dim strSubject
Dim strBodyText
Dim myMaster
myMaster = ActiveWorkbook.Name
Const olMailItem = 0
Dim rece
rece = Array("Syed Iqbal", "Zahid Qamar", "Ishtiaq Khan", "Aamir Zakaria")
For q = 0 To 5
strReceipent = rece(q)
strSubject = "Incoming time report from 1 September to 15 September 2002"
'or you can use the specific cell address which is a variable data
With ActiveSheet.Range("b:b")
Set xFind = .Find(rece(q), LookIn:=xlValues, LookAt:=xlWhole)
Range(xFind.Address).Select
If Not xFind Is Nothing Then
FstOccurance = xFind.Address
Do
Set xFind = .FindNext(xFind)
Loop While Not xFind Is Nothing And xFind.Address <> FstOccurance
End If
End With
Dim a
a = Selection.EntireRow.Address
Range("5:5," & a).Select
Selection.Copy
Workbooks.Add
ActiveSheet.Paste
Columns("A:A").EntireColumn.AutoFit
Columns("B:B").EntireColumn.AutoFit
ActiveWorkbook.SendMail (rece(q))
Set objOutlook = CreateObject("Outlook.application")
Set objNameSpace = objOutlook.GetNamespace("MAPI")
Set mItem = objOutlook.CreateItem(olMailItem)
mItem.To = strReceipent
mItem.Subject = strSubject
mItem.Save
mItem.Send
Workbooks("myMaster").Activate
If strReceipent = "" Then
MsgBox "No Receipient provided. Mail not sent", vbInformation, "Mail Error"
End If
Next q
' **** Clean up
'
Set mItem = Nothing
Set objNameSpace = Nothing
Set objOutlook = Nothing
End Sub