Results 1 to 2 of 2

Thread: Pasting RTF text into Outlook note

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    1

    Question Pasting RTF text into Outlook note

    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...

    VB Code:
    1. Function SendHTMLeMail(ToList As String, CCList As String, BCCList As String, _
    2.                    SubjectText As String, MsgText As String, Method As String) As Boolean
    3. '***************************************************************
    4. '    Purpose: Sends or displays an Oulook message
    5. '      INPUT: ToList:     ID's that will go on the To: line
    6. '             CCList:     ID's that will go on the CC: line
    7. '             BCCList:    ID's that will go on the BCC: line
    8. '             SubjectText:Text for the subject line
    9. '             MsgText:    Text for the body of the message
    10. '             Method:     String to determine to Send or Display
    11. '     Output: True or False
    12. '***************************************************************
    13.  
    14.   Dim olMAPI As New Outlook.Application
    15.   Dim itmMail As Outlook.MailItem
    16.  
    17.   Set itmMail = olMAPI.CreateItem(olMailItem)
    18.   With itmMail
    19.     .To = ToList
    20.     .CC = CCList
    21.     .BCC = BCCList
    22.     .Subject = SubjectText
    23.     .BodyFormat = olFormatHTML
    24.     .HTMLBody = "<HTML><Head></Head><Body>"
    25.     .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>"
    26.     .HTMLBody = .HTMLBody & "<tr bgcolor=OldLace><td><hr></td></tr>"
    27.     .HTMLBody = .HTMLBody & "<tr bgcolor=OldLace><td><font style=color:navy;font-size:12pt;>"
    28.  
    29.     .HTMLBody = .HTMLBody & "<tr bgcolor=OldLace><td><font style=color:navy;font-size:12pt;>" & MsgText & "</font></td></tr>"
    30.  
    31.     .HTMLBody = .HTMLBody & "<tr bgcolor=OldLace><td><hr></td></tr></table>"
    32.     .HTMLBody = .HTMLBody & "</body></html>"
    33.   End With
    34.  
    35.   If Method = "Send" Then
    36.     itmMail.Send
    37.   Else
    38.     itmMail.Display
    39.   End If
    40.  
    41.  
    42. End Function

    I can automate Word to open the .RTF file and copy the contents...
    VB Code:
    1. Dim oApp As New Word.Application
    2.   Dim oAbstractDoc As Word.Document
    3.   Dim oAbstractRange As Word.Range
    4.  
    5.     oApp.Visible = True
    6.     Set oAbstractDoc = oApp.Documents.Open(RTFFileName)
    7.     Set oAbstractRange = oAbstractDoc.Range
    8.     With oAbstractRange
    9.       .Select
    10.       .Copy
    11.     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

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Pasting RTF text into Outlook note

    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.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width