+ Reply to Thread
Results 1 to 4 of 4

Keeping break lines from textbox when sending email

  1. #1
    Registered User
    Join Date
    02-15-2014
    Location
    London
    MS-Off Ver
    Excel 2013
    Posts
    42

    Keeping break lines from textbox when sending email

    Hello everyone,

    There is an issue I can't solve and I'd like your advice on this one.

    I have an Excel sheet with a textbox and a "Send" button.
    User can put their comments in the textbox and then press "Send" to automatically send an email with the file attached and a generic subject/body line ("Please find attach my comments").

    My problem:

    In the email's body, I would like to include the content of the textbox, so I don't have to open the file to read the comment.
    The thing is, break lines are not included and it looks like a wall of text.

    Example:

    If I use

    strBody = "Hi there,<br><br>" & vbNewLine & "Please find attached my comments" & vbNewLine & "Thanks," & vbNewLine & Comments.commentsdetails

    strSubject = "My Comments"
    and if the textbox "commentsdetails" contains:

    Hello, this is a test.
    Thank you for reading my comment.
    The email's body will look like this:

    Hi there,
    Please find attached my comments
    Thanks,

    Hello, this is a test.Thank you for reading my comment.
    instead of

    Hi there,
    Please find attached my comments
    Thanks,

    Hello, this is a test.
    Thank you for reading my comment.

    Is there any way to include all break lines from the textbox in my email's body?

    Please let me know if I am unclear or if you need any additional details.

    And as always, thank you for your help.

  2. #2
    Valued Forum Contributor quekbc's Avatar
    Join Date
    01-18-2010
    Location
    Sydney, Australia
    MS-Off Ver
    2010, 2013, 2016
    Posts
    1,149

    Re: Keeping break lines from textbox when sending email

    How are you extracting the content of the textbox?

    I do not have Outlook installed on this system but testing it on MsgBox, Debug.Print and the InStr function tells me that there is a line feed character - Chr(10) or vbLf.

    I used
    Please Login or Register  to view this content.
    to extract the content of the text box.

    Hope this helps.

  3. #3
    Registered User
    Join Date
    02-15-2014
    Location
    London
    MS-Off Ver
    Excel 2013
    Posts
    42

    Re: Keeping break lines from textbox when sending email

    Hello quekbc,

    Thank you very much for your reply.
    I'm afraid I'm not sure how I can use your code in this case...

    Just to give you more info on how the email is sent (I'll do my best to explain, though it is not my code):



    The email body text is in the cell E158, with this VBA code:

    Please Login or Register  to view this content.
    To send the email with Outlook, a window (form) with the email subject/body is displayed. When pressing the "Send" button, the following code is used:

    Please Login or Register  to view this content.
    The code may be messy and there are many modules as well, so I hope I'm not too confusing.

    I tried again and even if the cell E158 (email's body) contains the following text:

    Hello,
    This is a test.

    The content in the email will be displayed as:

    Hello,this is a test.
    Last edited by Leith Ross; 10-22-2014 at 06:06 PM. Reason: Change Quote Tags To Code Tags

  4. #4
    Registered User
    Join Date
    02-15-2014
    Location
    London
    MS-Off Ver
    Excel 2013
    Posts
    42

    Re: Keeping break lines from textbox when sending email [SOLVED]

    Sorry for the double post.

    Quekbc's post gave me an idea and I realise that there was an easy solution.

    The cell E158 contains the email's body text.
    I just used the cell H158 with the formula

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    This replaces break lines with <br> since the email actualy uses html codes (I didn't think of that).
    So now, the email's body looks fine.

    I edited the thread title with [SOLVED]. I'll come back here if it turns out that my solution doesn't work.
    I hope this can help someone facing the same issues someday.
    Last edited by Leith Ross; 10-22-2014 at 06:07 PM. Reason: Added Formula Tags

+ 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. olMail - Email Attachment Variable. Sending Email through Excel
    By ShakJames in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-23-2014, 07:55 AM
  2. olMail - Email Attachment Variable. Sending Email through Excel
    By ShakJames in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-23-2014, 07:41 AM
  3. Sending Email from VBA - selecting correct email address issue
    By Rachieo in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-27-2014, 03:51 PM
  4. Sending email while keeping the zoom format.
    By VoodooChild in forum Outlook Formatting & Functions
    Replies: 1
    Last Post: 07-16-2010, 05:03 AM
  5. [SOLVED] Break cell into multiple lines by line break
    By Chia in forum Excel General
    Replies: 1
    Last Post: 08-20-2006, 01:40 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