Hello Sir,
Hope you are doing Great, Sir what if I want to use worksheet(ws3) range (a1: t28) as a email body . how it can be done ?
Thank you
Code
[align=left][COLOR=#252C2F][FONT=Courier][SIZE=12px]Sub EmailByDateDue3()
Dim ws As Worksheet, ws2 As Worksheet, r As Range, c As Range
Dim f As Range, sig$, SentOnBehalfOfName$, body$, user$
'Late binding
Dim olApp As Object, olMail As Object, Word As Object, wr As Object
'Early binding
'Tools > References > Microsoft Outlook xx.0 Object Library
'Dim olApp As Outlook.Application, olMail As Outlook.MailItem
'Tools > References > Microsoft Word xx.0 Object Library
'Dim Word As Document, wr As Word.Range
'****************** INPUTs ***************************************
Set ws = Worksheets("Data")
Set ws2 = Worksheets("Email sent Report")
set ws3 = worksheet ("body")
'Signature file path, must exist.
SentOnBehalfOfName = "[email protected]"
sig = "C:\Users\PrakashPC\Desktop\New folder\Signature.rtf"
user = Environ("username")
'****************** END INPUTs ***********************************
If Dir(sig) = "" Then
MsgBox sig, vbApplicationModal, "Macro Ending - File Does Not Exist"
Exit Sub
End If
If user <> "PrakashPC" Or getUserName() <> "prakash" Then Exit Sub
'100 day column
Set r = ws.Range("G2", ws.Cells(Rows.Count, "G").End(xlUp))
'Set olApp = New Outlook.Application 'Early binding
'Set olApp = GetObject(, "Outlook.Application") 'Late binding
Set olApp = CreateObject("Outlook.Application")
For Each c In r
If c < 95 Or c > 100 Then GoTo NextC 'Not due yet so skip.
Set f = ws2.Columns("A").Find(ws.Cells(c.Row, "A"), ws2.[A1])
If Not f Is Nothing Then GoTo NextC
Set olMail = olApp.CreateItem(0) 'olMailItem=0
With olMail
.Importance = 1 'olImportanceNormal=1
.To = ws.Cells(c.Row + 1, "e")
.SentOnBehalfOfName = SentOnBehalfOfName
.Subject = "100 Day Reminder"
body = range.ws3("a1:t28").value
.GetInspector.Display
Set Word = .GetInspector.WordEditor
Set wr = Word.Content
wr = body
GetObject(sig).Content.Copy
wr.Collapse Direction:=0 'wdCollapseEnd=0
wr.Paste 'Paste at end
'.DeferredDeliveryTime = Now + TimeValue("00:10:00")
.Display
'.Send
'Write entry to log sheet.
Set f = ws2.Cells(Rows.Count, "A").End(xlUp).Offset(1)
f = ws.Cells(c.Row, "A") 'Serial Number
f.Offset(, 1) = ws.Cells(c.Row, "e") 'Name
f.Offset(, 2) = ws.Cells(c.Row + 1, "e") 'Email
f.Offset(, 3) = Date 'Reminder Sent
f.Offset(, 3).NumberFormat = "dd/mm/yyyy"
f.Offset(, 4) = ws.Cells(c.Row, "AS")
End With
NextC:
Next c
On Error Resume Next
Set olMail = Nothing
Set olApp = Nothing
End Sub[/SIZE][/FONT][/COLOR][/align]
[FONT=Courier]
Display More
[/FONT]