Email from excel issue - addding text

wmtsub

Active Member
Joined
Jun 20, 2018
Messages
322
Here is a portion of the macro I am using to email from a worksheet.
Everything works fine except when I try to add something to the Body of the email it is replacing the portion of the email with the data from excel. I am trying to add a predefined message in the body and then add the excel output below that. But I am stuck. Any ideas?


'Read the HTML file data and insert into the email body
Set objTextStream = objFileSystem.OpenTextFile(strTempHTMLFile)
objNewEmail.HTMLBody = Replace(objTextStream.readall, "align=center x:publishsource=", "align=left x:publishsource=")
objNewEmail.Display
'****************************************************************************************
tm = "Test Message "
'Specify email recipients, subjects ; etc, Here
'objNewEmail.Send '--> directly send out this email
objNewEmail.To = mr
'objNewEmail.Cc = ""
objNewEmail.Body = tm
objNewEmail.Subject = "Your Past Due ETA's " & tdd
'objNewEmail.attachments.add=
'****************************************************************************************
objTextStream.Close
objTempWorkbook.Close (False)
objFileSystem.DeleteFile (strTempHTMLFile)
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
.
Here is a different approach. Will it work for your needs ?

Code:
Option Explicit


Sub EmailSend()
Dim OutApp As Object
    Dim OutMail As Object
    Dim strbody1 As String
    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)


strbody1 = "<p>Dear Name:" & "<br><br>" & _
                "Please see attached for your latest balance." & "<br><br>" & _
                "Regards," & "<br><br>" & _
                "Finance</p>"


    On Error Resume Next
    With OutMail
        .to = "xyx"
        .CC = "xyx"
        .BCC = "xyz"
        .Subject = "Subject"
        .HTMLBody = strbody1
        .Display
        '.Send
    End With
    On Error GoTo 0
    Set OutMail = Nothing
    Set OutApp = Nothing
End Sub
 
Upvote 0
Maybee but it does not pick up the data from excel and when I ran it ti was very slow. The script i am using is quote quick and is working except I think that both the HTML and the Body tex are printing inthe same place so the first is being deleted by the second.
 
Upvote 0
.
I'm sorry ... but I could not get your macro to work here.
 
Upvote 0
Not really as it is not picking up data fromthe excel spreadsheet. Thanks though. And i got it solved..
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top