PDA

View Full Version : align email body from excel



tommy1234
01-17-2009, 11:34 AM
Hello
i wrote a code which transfer data from excel to outlook email body.
i have to align the text to the right, but i don't know how.

Thank you
P.S
i need the "strbody" to be align left



Sub mail_person()
Dim a As Integer, b As Integer
Dim OutApp As Object
Dim OutMail As Object
Dim strbody As String, combine As String, item As String, item_name As String, strbody1 As String
a = 1
If arr > 1 Then
For concatenate = a To arr - 1
x = x & "LRU Name : " & LRU1(a) & " " & "Quantity : " & LRU_quantity(a) & Chr(10)
a = a + 1
Next
Else
x = ""
End If
item = Worksheets("sheet1").Range("b2").Value
item_name = Worksheets("sheet1").Range("b3").Value
Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(0)
strbody = "Hello" & vbNewLine & vbNewLine & _
"This email was sent to update you on obsolite items " & _
"in your project : " & pro_code & vbNewLine & _
"Inventory : " & inventory & vbNewLine & _
"price : " & price & vbNewLine & _
"LRU Name : " & pro_inner_code & " " & "Quantity : " & sum_quantity & vbNewLine & _
x & vbNewLine & vbNewLine & _
"Best regards" & vbNewLine & vbNewLine & name

On Error Resume Next
With OutMail
.To = ""
.CC = ""
.BCC = ""
.Subject = "Program Obsolite Update -" & item
.Body = strbody & strbody1
.display 'or use .sent
End With
On Error GoTo 0


End Sub


Edit: VBA tags added to code. Select your code when posting and hit the vba button to format it for the forum.

lucas
01-17-2009, 11:57 AM
I don't know how to do this but I also don't understand the question. What exactly do you want aligned right?

tommy1234
01-17-2009, 03:16 PM
Hello

strbody represent the body of the email. i wrote some text in this part and i want this text to be align to the right when it appear as new email.

Thank you

jfournier
01-20-2009, 08:41 AM
You may try setting OutMail.HTMLBody instead of .Body, and try wrapping the .HTMLBody in "<p align="center">" and "</p>". Sincy you have multiple lines you probably will need to do the "<p align="center">" and "</p>" for each line you have, so you'd want to make a constant like:

Const htmLeftStart = "<p align="left">"
Const htmLeftEnd = "</p>"
strbody = htmLeftStart & "Hello" & htmLeftEnd & vbNewLine & vbNewLine & htmLeftStart & _
"This email was sent to update you on obsolite items " & _
"in your project : " & pro_code & htmLeftEnd & vbNewLine & htmLeftStart & _
"Inventory : " & inventory & htmLeftEnd & vbNewLine & htmLeftStart .....



I think that'd work for you...