PDA

View Full Version : Outlokk MAcro to Maintain the text formating



prasadsaurav
04-11-2012, 07:52 PM
Hi

I m trying to send mail through outlook with the help of excel macro.
Everything is working fine , except the text formating.

my macro takes the text from a word file that has a text with different color, and font.

whenever it is coming into outlook through macro, all the text properties is lost.

please suggest.

my code
Sub mail()

Dim objOutlook As Object
Dim objOutlookMsg As Object
Set objOutlook = CreateObject("Outlook.Application")
Set objOutlookMsg = objOutlook.CreateItem(0)
Dim OL As Object, MailSendItem As Object
Dim W As Object
Dim MsgTxt As String, SendFile As String
Dim ToRangeCounter As Variant
SendFile = Application.GetOpenFilename(Title:="Select MS Word " & "file to mail, then click 'Open'", _
buttontext:="Send", MultiSelect:=False)
Set W = GetObject(SendFile)
MsgTxt = W.Range(Start:=W.Paragraphs(1).Range.Start, End:=W.Paragraphs(W.Paragraphs.Count).Range.End)
Set W = Nothing
With objOutlookMsg
.Display
.To = "abc@yahoo.com"
'.Cc = "ifneed@copy.com"
.Subject = "Hello World"
'.Font.Bold = True
'.BodyFormat = olFormatRichText
.BodyFormat = olFormatHTML
.HTMLBody = MsgTxt
'.HTMLBody = "HTML version of message"
'.Attachments.Add ("c:\myFileToSend.txt")
End With
Set objOutlookMsg = Nothing
Set objOutlook = Nothing
End Sub