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:
To convert from HTML code to Body code:
See the attached file which demonstrates the above concepts and contains the following code in ordinary code module ModOutlookBodyVsHTMLBody:
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:
This option requires all variables to be declared and will give a compiler error for undeclared variables.
Lewis
Bookmarks