Solved

Complex email sent from excel

Posted on 2016-10-18
8
60 Views
Last Modified: 2016-11-04
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)
0
Comment
Question by:Sam Coombes
  • 3
  • 3
8 Comments
 
LVL 33

Expert Comment

by:Norie
ID: 41848511
What exactly do you want to appear in the email?
0
 

Author Comment

by:Sam Coombes
ID: 41848728
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
0
 
LVL 14

Accepted Solution

by:
frankhelk earned 500 total points
ID: 41851613
Hmm ... the property .Body is just a simple string, as far as I remember. In your code, when assigning

.Body = "Hi there" & (...)

you overwrite the previous assigned value from the statement

.Body = Cells(ActiveCell.Row, 9)

The second assignment should look like

.Body = .Body & vbcrlf & "Hi there" & (...)

to preserve that. Besides of that, the first assignment should read

.Body = Cells(ActiveCell.Row, 9).Value

because your statement assigns a Range object to a string property ... maybe that the implicit cast will get that right, but it's not good practice to rely on such constructs ... they might backfire later on when some update of VB won't permit that cast anymore or the cast leads to another result.
0
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 

Author Comment

by:Sam Coombes
ID: 41852383
That's great thank you but how do I insert lines spaces. So for example

Dear Dr Doctor


Could you please etc
0
 
LVL 14

Expert Comment

by:frankhelk
ID: 41853398
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 ...
1
 

Author Comment

by:Sam Coombes
ID: 41853516
Thank you very much thats great
0
 
LVL 14

Expert Comment

by:frankhelk
ID: 41853840
You're welcome ... I would be pleased to get the points for that solution ;-)
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article lists the top 5 free OST to PST Converter Tools. These tools save a lot of time for users when they want to convert OST to PST after their exchange server is no longer available or some other critical issue with exchange server or impor…
This article explains how to install and use the NTBackup utility that comes with Windows Server.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question