I need help on the following desperately
I need to write a macro to send out 2 types of email via excel 2000 for those (DEPENDING ON their Action_Item_Status
1)action items with Action_Item_Status='Overdue', (over due email)
1)action items with Action_Item_Status='Due Soon', (reminder email)

Action_Status_As_Of_Today can have these values:-Done,Overdue,Due Soon,Not Due Yet

My datasheet contains the following columns:-
Action_source(filename-worksheet_name) 'column A'
Status_Item 'column B'
Status_Item_details 'column C'
Action_Due_date 'column D'
Action_Party 'column E'
Action_Party_Email 'column F'
Classification_of_Status 'column G'
Action_Status 'column H'
Action_Status_As_Of_Today 'column I'

The 'Action_Party_Email' can be duplicated.(Ie. the same email address can be found in different 'Action_Item_No' records.

In each email, i need to also include the data found in 'Status_Item' & "Action_Due_date" columns.

Please kindly help.Thanks alot in advanced:)

Below is my sample code

Sub Button1_Click()
' Button1_Click Macro
' Macro recorded 5/22/2007 by Registered User
' Don't forget to copy the function RangetoHTML in the module.
' Working in Office 2000-2007
Dim OutApp As Object
Dim OutMail As Object
Dim cell As Range
Dim rng As Range
Dim Ash As Worksheet

Set Ash = ActiveSheet
On Error GoTo cleanup
Set OutApp = CreateObject("Outlook.Application")

With Application
.EnableEvents = False
.ScreenUpdating = False
End With

For Each cell In Ash.Columns("F").Cells.SpecialCells(xlCellTypeConstants)
If cell.Value Like "?*@?*.?*" And LCase(cell.Offset(0,1).Value) = "Overdue" Then
Ash.Range("A1:S100").AutoFilter Field:=6, Criteria1:=cell.Value

With Ash.AutoFilter.Range
On Error Resume Next
Set rng = .SpecialCells(xlCellTypeVisible)
On Error GoTo 0
End With

Set OutMail = OutApp.CreateItem(0)

On Error Resume Next
With OutMail
.To = cell.Value
.Subject = "Updates"
.HTMLBody = RangetoHTML(rng)


End With
On Error GoTo 0

Set OutMail = Nothing
Ash.AutoFilterMode = False
End If
Next cell

Set OutApp = Nothing
With Application
.EnableEvents = True
.ScreenUpdating = True
End With

End Sub

Function RangetoHTML(rng As Range)

Dim fso As Object
Dim ts As Object
Dim TempFile As String
Dim TempWB As Workbook

TempFile = Environ$("temp") & "\" & Format(Now, "dd-mm-yy h-mm-ss") & ".htm"

'Copy the range and create a new workbook to past the data in
Set TempWB = Workbooks.Add(1)
With TempWB.Sheets(1)
.Cells(1).PasteSpecial Paste:=8
.Cells(1).PasteSpecial xlPasteValues, , False, False
.Cells(1).PasteSpecial xlPasteFormats, , False, False
Application.CutCopyMode = False
On Error Resume Next
.DrawingObjects.Visible = True
On Error GoTo 0
End With

'Publish the sheet to a htm file
With TempWB.PublishObjects.Add( _
SourceType:=xlSourceRange, _
Filename:=TempFile, _
Sheet:=TempWB.Sheets(1).Name, _
Source:=TempWB.Sheets(1).UsedRange.Address, _
.Publish (True)
End With

'Read all data from the htm file into RangetoHTML
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.GetFile(TempFile).OpenAsTextStream(1, -2)
RangetoHTML = ts.readall
RangetoHTML = Replace(RangetoHTML, "align=center x:publishsource=", _
"align=left x:publishsource=")

'Close TempWB
TempWB.Close savechanges:=False

'Delete the htm file we used in this function
Kill TempFile

Set ts = Nothing
Set fso = Nothing
Set TempWB = Nothing
End Function

9 Years
Discussion Span
Last Post by DenisOxon


Firstly you do not appear to tell us what the problem is ?

Secondly do you have outlook set up ?

Thirdly have you thought of doing it as mail merge from word ?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.