Formating help with VBA

peter_z

Board Regular
Joined
Feb 27, 2011
Messages
87
Hey Guys

I need my txt to display like this:

[Opening free format]<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<o:p> </o:p>
The file attached to this email contains a schedule of the policies you have placed with us which:
<o:p></o:p>
· XXXXX
· XXXXX

XXX
<o:p> </o:p>
XXX
<o:p> </o:p>
XXX
<o:p> </o:p>
[Closing free format]<o:p></o:p>

I have the following code in vba:

Code:
 aEmail.body = "[Opening free format]" _
& "The file attached to this email contains a schedule of the policies you have placed with us which: " _
& "[FONT=Calibri]XXXXX[/FONT]" _
& "[FONT=Calibri]XXXXX[/FONT] " _
& "XXX " _
& "XXX " _
& "XXX " _
& "[Closing free format]" 'Change Body Message

But it will come out like this: The file attached to this email contains a schedule of the policies you have placed with us which: XXXXX XXXX XXX XXX XXX [Closing free format]

Any help would be much appreciated.

THANKS HEAPS IN ADVANCE!

[Opening free format]
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
try this

Code:
aEmail.body = "[Opening free format]" _
& "The file attached to this email contains a schedule of the policies you have placed with us which: " _
& vbLf & "XXXXX" _
& vbLf & "XXXXX " _
& vbLf & "XXX " _
& vbLf & "XXX " _
& vbLf & "XXX " _
& vbLf & "[Closing free format]" 'Change Body Message
 
Upvote 0
Is it just the carraige return you want, not the bullets and other formatting?
 
Upvote 0
Peter

You would need to use HTMLBody instead of Body, and of course the HTML code to get that formatting.

Here's how you can do the bulleted list.
Code:
Dim strHTML As String
 
    strHTML = "< ul>"
    strHTML = strHTML & "< li>XXXX"
    strHTML = strHTML & "< li>XXXX"
    strHTML = strHTML & "< /ul>
 
    strHTML = Replace(strhtml, " ", "")
...
   aEmail.HTMLBody = strHTML
Note, the only reason for the Replace is to get rid of the spaces I had to add so the HTML would appear on the board.

In HTML you can use the BR tag for line breaks.
PS You are using Outlook aren't you?
 
Upvote 0
:biggrin: Just fiddled around with the code a bit more works perfect.

Thanks a lot for your help Boller, Dryver14 and Norie!
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,726
Members
452,939
Latest member
WCrawford

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top