+ Reply to Thread
Results 1 to 4 of 4

How To Replace One Line From Email Body With New Line

  1. #1
    Registered User
    Join Date
    02-04-2016
    Location
    Maharashtra
    MS-Off Ver
    2009
    Posts
    18

    How To Replace One Line From Email Body With New Line

    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

  2. #2
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: How To Replace One Line From Email Body With New Line

    upendra,

    It is critical, especially with long code, to use code tags as per the forum rules (rule#3)

    Sorry but it is our policy to require the correction to be made before people reply with solutions.
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  3. #3
    Registered User
    Join Date
    02-04-2016
    Location
    Maharashtra
    MS-Off Ver
    2009
    Posts
    18

    Re: How To Replace One Line From Email Body With New Line

    Hi Team,

    Simply I am looking for a code which will help me to replace one line from the message body which was already sent. I need help to replace one particular line from sent message when forwarding to other.

    If anybody have the solution for the same please provide. I my coding I have used below line to replace the same but it's not working.

    With msg.ReplyAll
    .SentOnBehalfOfName = sname
    .To = dsht.Range("E" & i).Value
    .CC = dsht.Range("F" & i).Value
    .HTMLBody = Replace(msg.HTMLBody, "Please Use This Code For Future Use", "Here is the code number for your use") ' To replace one line from body
    .Subject = Replace(msg.Subject, "1st Reminder", "Closure of Pending Claim(s)")
    .Display
    End With

  4. #4
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,601

    Re: How To Replace One Line From Email Body With New Line

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here



    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Range not working in body line
    By Sam Hatch in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-26-2016, 11:11 AM
  2. Possible to Email a Spreadsheet, Line By Line?
    By sum_weirdo in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 06-17-2014, 06:34 PM
  3. Can't enter more than 1 line of text in body of email
    By moyay4 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-25-2013, 01:41 PM
  4. Multi line email body from HYPERLINK CONCATENATE MAILTO?
    By JRR007 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 10-23-2012, 08:18 AM
  5. [SOLVED] Create macro to send worksheet as body of email using cells as subject line
    By LindaABH in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-16-2012, 07:43 PM
  6. Replies: 4
    Last Post: 02-27-2012, 03:13 AM
  7. Macro to email contents of cell line by line
    By drew_f_taylor in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-18-2007, 06:48 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1