PDA

Click to See Complete Forum and Search --> : Pasting RTF text into Outlook note


Zero_Duck
Jan 18th, 2006, 08:15 AM
I am using VB6, MS SQL Server and MS Office 2003.

I have the following function that accepts several Outlook related parameters and uses them to prepare a note and either send it or display it depending on the contents of the "Method" param. I was originally getting all of the data from various fields from a SQL database, putting in some HTML formatting tags and sending it on its merry way. That worked wonderfully.

Then I was asked to provide the users a way to format part of the text on their own from within my application. I found a neat control from TX Text Control to use for my purposes and save the contents of that text control as an .RTF file. My issue now is how to retain or recreate the formatting I have as HTML while programmatically inserting the contents of the .RTF file at a specific point in the Outlook note?

My current code which works just fine...


Function SendHTMLeMail(ToList As String, CCList As String, BCCList As String, _
SubjectText As String, MsgText As String, Method As String) As Boolean
'***************************************************************
' Purpose: Sends or displays an Oulook message
' INPUT: ToList: ID's that will go on the To: line
' CCList: ID's that will go on the CC: line
' BCCList: ID's that will go on the BCC: line
' SubjectText:Text for the subject line
' MsgText: Text for the body of the message
' Method: String to determine to Send or Display
' Output: True or False
'***************************************************************

Dim olMAPI As New Outlook.Application
Dim itmMail As Outlook.MailItem

Set itmMail = olMAPI.CreateItem(olMailItem)
With itmMail
.To = ToList
.CC = CCList
.BCC = BCCList
.Subject = SubjectText
.BodyFormat = olFormatHTML
.HTMLBody = "<HTML><Head></Head><Body>"
.HTMLBody = .HTMLBody & "<table border=0 align=center><tr bgcolor=tomato><td align=center><font style=color:white;font-size:14pt;>This automated message is being sent to you by the Proprietary Document Central (PDC) website.<br>You will find important information and/or instructions below this announcement.</font></td></tr>"
.HTMLBody = .HTMLBody & "<tr bgcolor=OldLace><td><hr></td></tr>"
.HTMLBody = .HTMLBody & "<tr bgcolor=OldLace><td><font style=color:navy;font-size:12pt;>"

.HTMLBody = .HTMLBody & "<tr bgcolor=OldLace><td><font style=color:navy;font-size:12pt;>" & MsgText & "</font></td></tr>"

.HTMLBody = .HTMLBody & "<tr bgcolor=OldLace><td><hr></td></tr></table>"
.HTMLBody = .HTMLBody & "</body></html>"
End With

If Method = "Send" Then
itmMail.Send
Else
itmMail.Display
End If


End Function


I can automate Word to open the .RTF file and copy the contents...

Dim oApp As New Word.Application
Dim oAbstractDoc As Word.Document
Dim oAbstractRange As Word.Range

oApp.Visible = True
Set oAbstractDoc = oApp.Documents.Open(RTFFileName)
Set oAbstractRange = oAbstractDoc.Range
With oAbstractRange
.Select
.Copy
End With



...but then, how can I get the copied .RTF text pasted into the Outlook note?

I'm sorry if this went on too long, but I'd rather give too much instead of too little information. Many thanks for your help.

Zero_Duck

RobDog888
Jan 18th, 2006, 11:04 AM
What about opening the rtf file using Basic File I/O as a text file. Then you can read the rtf formatting characters and all.