+ Reply to Thread
Results 1 to 10 of 10

Format E-mail Body

  1. #1
    Registered User
    Join Date
    12-31-2015
    Location
    Barreiro, Portugal
    MS-Off Ver
    MS Office 365
    Posts
    84

    Format E-mail Body

    Hello everyone,

    Can someone help me to format my e-mail body to the same as the default format of the e-mails?

    I have .htmlbody because the Signature contains an image.

    Also, the message is in a worksheet, but now I lost the breaks between lines of the cells.

    eg:

    Hello,

    Regards.

    Now is:

    Hello, Regards.

    Here's the code:

    Please Login or Register  to view this content.
    Thank you for your help.

  2. #2
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Format E-mail Body

    Sorry, I do not understand your question.
    Email body has no default, it is the text you place in it.
    The only possibilities are plain text, HTML or RTF.
    So what is your question? What you you want as a result?

    Maybe a sample file with your explanation would help.
    Last edited by Keebellah; 02-25-2017 at 05:01 AM. Reason: Additional Information
    ---
    Hans
    "IT" Always crosses your path!
    May the (vba) code be with you... if it isn't; start debugging!
    If you like my answer, Click the * below to say thank-you

  3. #3
    Registered User
    Join Date
    12-31-2015
    Location
    Barreiro, Portugal
    MS-Off Ver
    MS Office 365
    Posts
    84

    Re: Format E-mail Body

    Hello, thank you for your reply.

    What I mean by default format does not refer to the code. When you create a new e-mail with outlook, you already have a format for the text you are going to write.
    I want the cells from the worksheet to be in that format.

    Here's the result I have:

    Capturar.PNG

    And here's what I want:

    Capturar1.PNG

    Just one thing that will also add difficulty to the case: the message i need to format is not always the same, so the line break will not occur always in the same place.

    When I had .body, although i couldn't get the signature, the cells was copied correctly, but now, not only it is pasted as plain text, it also loses the line breaks.

    Thank you for your help.

  4. #4
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Format E-mail Body

    Hi Rui,

    To solve your problem, you have to understand the difference between an Outlook Email .Body and .HTMLBody.

    When sending an Email using Outlook, the Email Body can be either .Body or .HTMLBody:
    a. Body uses ASCII code for a NEW LINE which can be one of:
    (1) Carriage Return LineFeed - the combination of Characters Chr(13) and Chr(10) which can also be coded as vbCrLf.
    (2) LineFeed Only - Chr(10) which can also be coded as vbLf.
    (3) Carriage Return Only - Chr(13) which can also be coded as vbCr.
    NOTE: The above numbers are decimal numbers (e.g. the ASCII code for Linefeed is Decimal 10).

    b. HTMLBody uses HTML code to indicate a NEW LINE. The HTML Code for NEW LINE is <BR> .

    c. To switch between .Body and .HTMLBody, the appropriate NEW LINE code must be used.

    For example if reading code from a Cell and to convert to HTML:
    Please Login or Register  to view this content.

    To convert from HTML code to Body code:
    Please Login or Register  to view this content.

    See the attached file which demonstrates the above concepts and contains the following code in ordinary code module ModOutlookBodyVsHTMLBody:
    Please Login or Register  to view this content.
    It is a best practice to declare all variables. If you misspell a variable in your code, VBA will silently assume it is a Variant variable and go on executing with no clue to you that you have a bug. Go to the VBA development window, click Tools, Options, and check "Require Variable Declaration." This will insert the following line at the top of all new modules:
    Please Login or Register  to view this content.
    This option requires all variables to be declared and will give a compiler error for undeclared variables.

    Lewis

  5. #5
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Format E-mail Body

    You got your answer and solution

  6. #6
    Registered User
    Join Date
    12-31-2015
    Location
    Barreiro, Portugal
    MS-Off Ver
    MS Office 365
    Posts
    84

    Re: Format E-mail Body

    Thank you very much for your explanation.

    For the line breaks, the problem is solved (although I will need more time to understand it all, because the ASCII part is completely new to me). I have the cell in my worksheet to read as HTML and it works thanks to you.

    The thing is, to have my signature, which contains an image, I need to have .htmlbody, right? But that way, how can i keep the format on the body? Because when I convert to .body, I loose the image from the signature. I've tried to convert to .body and then convert back to .htmlbody but that does not seem to do the trick.

    Anyway, thank you for the explanation. Not only you tried to help with the problem, but also provided a way to learn the basis, so I am grateful for your answer.

    PS: thank you for the Variable Declaration advice. It's a nice control to have.

  7. #7
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Format E-mail Body

    To add the signature, try the following (new code in red):

    Please Login or Register  to view this content.
    Lewis

  8. #8
    Registered User
    Join Date
    12-31-2015
    Location
    Barreiro, Portugal
    MS-Off Ver
    MS Office 365
    Posts
    84

    Re: Format E-mail Body

    With the workbook you provided, and with the change you made above, the result is this:

    Capturar.PNG

    where the bottom part is the logo (image) I have in the signature.

    Trying it in the Convert 'B14' to .Body, this is the result:

    Capturar1.PNG

    Where no logo appears.

    So here you can see my dilemma. I either have the body formatted the way I want it but without the Signatures logo, or have the Signature alright but not the body format.

    Anyway, thanks again for your efforts.

  9. #9
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Format E-mail Body

    Rui said:
    So here you can see my dilemma. I either have the body formatted the way I want it but without the Signatures logo, or have the Signature alright but not the body format.
    In Excel 2016, I was able to duplicate your problem.

    Outlook Font Types and Sizes.
    (1) My default is Calibri 11 (unchanged from Microsoft default) using Outlook 2016.
    (2) Creating Outlook Emails from Excel with the .Body command uses Font Calibri 12.
    (3) Creating Outlook Emails from Excel with the .HTMLBody command and no signature uses Font Times New Roman 12.
    (4) Creating Outlook Emails from Excel with the .HTMLBody command and signature uses Font Times New Roman 12 for the first paragraph and font Calibri 10 for other paragraphs.

    The good news was that I was able to workaround the problem using some HTML code to control the font name and the font size in the body, when a signature was used.

    See the attached demo file, which contains the following updated VBA code. Items of interest are in red.

    Hard Coded Font Name and Font Size (Module ModOutlookBodyVsHTMLBody):
    Please Login or Register  to view this content.

    Font Name and Font Size as variables in the code (Module ModZTest):
    Please Login or Register  to view this content.
    Font Name and Font Size as variables in the code with values obtained from the Spreadsheet (Module ModZTest):
    Please Login or Register  to view this content.
    Lewis

  10. #10
    Registered User
    Join Date
    12-31-2015
    Location
    Barreiro, Portugal
    MS-Off Ver
    MS Office 365
    Posts
    84

    Re: Format E-mail Body

    Thank you so much.

    I will use the second option you presented. I have multiple users for the code, so I need to keep the format flexible. Since I already have cells prepared to adapt according to each user (I have a userform when the excel opens to indicate the user - so it changes the default paths to linked workbooks), I will simply have to write the default formats.

    Once again, thank you very much. Not only did you help to solve the situation, but also provided a way to learn why I was having difficulties.

    All the best.

+ 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. Using HTML Body Format in Outlook mail
    By akash kothari in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-08-2014, 11:33 AM
  2. Format Outlook Mail Body using VBA
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-27-2014, 07:02 AM
  3. Replies: 1
    Last Post: 07-22-2012, 09:26 AM
  4. Word Format as Body of mail using Send mail
    By andy_iyeng in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-19-2012, 05:04 AM
  5. Excel 2007 : Email 2007 excel format in body of mail
    By dbdanboat in forum Excel General
    Replies: 1
    Last Post: 01-21-2011, 07:47 AM
  6. Format text in e-mail body
    By mabbutt in forum Outlook Formatting & Functions
    Replies: 4
    Last Post: 09-28-2009, 04:22 AM
  7. Possible to format the body in a mail using SendMail?
    By Dynelor in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-28-2008, 08:14 AM

Tags for this Thread

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