Hi All,
I am trying to replace whole line from previous email body while forwarding it to someone else. Their is no fix place that where this line will be appear in email body. But it sure that this line is their. I have used below code for the same. It will help me to replace subject line but not the body of the email.
Can someone help me to correct this coding or provide me a coding which already used for this kind of scenario. Also what if the particular line is in table format in body? Is it process as per the normal.
I am not having any challenge to run the code but the thing is that body line is not getting replaced.
Please help.
Code Used:
Sub Second_ReminderFromGroup() 'send 2nd reminders
Dim rng As Range
Dim fld As Outlook.MAPIFolder, folder As Outlook.MAPIFolder, afld As Outlook.MAPIFolder
Dim mitem As Outlook.MailItem, msg As Outlook.MailItem
Dim mbox As String, mfld As String
Dim x As Object, ermv As Object
Dim myNamespace As Outlook.Namespace
Dim rec As Outlook.Recipient, recs As Outlook.Recipients
Dim pa As Outlook.PropertyAccessor
Dim sval As String, sbtext As String
Set mwbk = ThisWorkbook
Set msht = mwbk.Worksheets("Master")
Set clsht = mwbk.Sheets("Claim Handler")
Set dsht = mwbk.Worksheets("Reminders")
Set myNamespace = Outlook.Application.GetNamespace("MAPI")
mbox = clsht.Range("I5").Value
mfld = clsht.Range("I7").Value
sname = clsht.Range("I9").Value
mesg1 = msht.Range("B57").Value
mesg2 = msht.Range("B53").Value
mesg3 = msht.Range("B55").Value
fmsg = mesg2 & "<br>" & "<br>" & mesg3 & "<br>" & "<br>"
' fpath = "C:\Users\Upender Mahato\Desktop\Copied Mails"
Set folder = myNamespace.Folders(mbox)
Set folder = folder.Folders(mfld)
If folder.Items.Count < 1 Then
MsgBox ("No Message In Inbox")
Exit Sub
Else
End If
lr = dsht.Range("B65000").End(xlUp).Row
For i = 2 To lr
sval = dsht.Range("B" & i).Value
sbtext = "1st Reminder"
If dsht.Range("J" & i).Value <> "" And dsht.Range("K" & i).Value = "" And dsht.Range("L" & i).Value = "" And dsht.Range("M" & i).Value = "" And dsht.Range("J" & i).Value <= Date - 7 Then
For j = folder.Items.Count To 1 Step -1
If VBA.DateValue(folder.Items.Item(j).SentOn) >= dsht.Range("G" & i).Value And InStr(folder.Items.Item(j).Body, sval) > 0 And InStr(folder.Items.Item(j).Subject, sbtext) > 0 Then 'folder.Items.Item(j).Subject = dsht.Range("H" & i).Value Then
If TypeName(folder.Items.Item(j)) = "MailItem" Then
Set msg = folder.Items.Item(j)
strHTML = msg.ReplyAll.HTMLBody
' dsht.Range("AL" & i).Value = msg.SentOn
If dsht.Range("E" & i).Value = "" Then
With msg.ReplyAll
.SentOnBehalfOfName = sname
.HTMLBody = Replace(msg.HTMLBody, "*" & mesg1 & "*", fmsg)
.Subject = Replace(msg.Subject, "1st Reminder", "Closure of Pending Claim(s)")
.Display
End With
Else
With msg.ReplyAll
.SentOnBehalfOfName = sname
.To = dsht.Range("E" & i).Value
.CC = dsht.Range("F" & i).Value
.HTMLBody = Replace(msg.HTMLBody, mesg1, fmsg) ' To replace one line from body
.Subject = Replace(msg.Subject, "1st Reminder", "Closure of Pending Claim(s)")
.Display
End With
End If
dsht.Range("J" & i).Value = Date
dsht.Range("N" & i).Value = "2nd Reminder & Closed"
GoTo nextii
Else
End If
Else
End If
Next j
Else
End If
nextii:
Next i
End Sub
Bookmarks