Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inserting text in Email body using VBA

Tags:

excel

vba

outlook

I am using the following VBA macro to mail a range of cells from Excel

ActiveSheet.Range("A2:Q133").Select
ActiveWorkbook.EnvelopeVisible = True

   With ActiveSheet.MailEnvelope
    .Introduction = "demo"
      .Item.To = "[email protected]"
      .Item.Subject = "Testing mail"
      .Item.Send
   End With 

I want to modify the code to insert some text in the end. I tried using

.Item.HTMLBody = "Random text"

but the mail doesnt contain the text.

Please let me know if i am doing anything wrong and what is the correct way to do it. Thanks in advance!

like image 257
user2862496 Avatar asked Mar 04 '26 08:03

user2862496


1 Answers

With MailEnvelope you send the whole sheet as body of your email.

Introduction allows you to add some text before a mail item, but you have no other way to add something at the end than append something to the Excel sheet.

Even if you modify the Body or the HTMLBody, this doesn't have effect on the email.

Maybe you could try to add same the message as draft and reopen it as a different object to modify it, but it seems over complicated. Much easier just to add some temporary text at the end of the excel spreasheet and remove it after .Item.Send

like image 89
mucio Avatar answered Mar 05 '26 21:03

mucio



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!