Avatar of Sam Coombes
Sam Coombes
 asked on

Complex email sent from excel

Can anyone tell me how to edit this code so I can enter a whole selection of cells throughout the email I wish to send. Currently I can only get the address and title and first line to come up, after that nothing I try will work.


Sub SendEMail()
   

    Dim OutApp As Outlook.Application
    Dim OutMail As Outlook.MailItem
    Dim strbody As String

    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(olMailItem)

   

    On Error Resume Next
    With OutMail
        .To = Cells(ActiveCell.Row, 19)
        .CC = ""
        .BCC = ""
        .Subject = Cells(ActiveCell.Row, 12)
        .Body = Cells(ActiveCell.Row, 9)
       
       
        .Body = "Hi there" & vbNewLine & vbNewLine & _
              "This is line 1" & vbNewLine & _
              "This is line 2" & vbNewLine & _
              "This is line 3" & vbNewLine & _
              "This is line 4"

        'SendUsingAccount is new in Office 2007
        'Change Item(1)to the account number that you want to use
        .SendUsingAccount = OutApp.Session.Accounts.Item(2)
Microsoft ExcelExchange

Avatar of undefined
Last Comment
Frank Helk

8/22/2022 - Mon
Norie

What exactly do you want to appear in the email?
Sam Coombes

ASKER
I need it to say dear -active cell 3, I would like to remind you that active cell 6, that this is due to expire on active cell 4  etc

Thank you
ASKER CERTIFIED SOLUTION
Frank Helk

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Sam Coombes

ASKER
That's great thank you but how do I insert lines spaces. So for example

Dear Dr Doctor


Could you please etc
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Frank Helk

That's no problem ... the term vbCrLf (a VB predefined constant) I've mentioned above would add a carriage return / line feed sequence. Add two, and you'll get a blank line in between. Add three, and ... I bet you've got the picture ;-)

P.S.: DON'T use that in header fields ...
Sam Coombes

ASKER
Thank you very much thats great
Frank Helk

You're welcome ... I would be pleased to get the points for that solution ;-)
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.