Results 1 to 5 of 5
  1. #1
    New Lounger
    Join Date
    Aug 2002
    Location
    New Hampshire, USA
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    RichText into Word via OLE (Word 2000)

    I'm trying to write OLE code to move data from one app (Lotus Notes email documents) into Word documents. Some of the data to be moved is fomatted text and, while I have the option to move in the text alone and loose the formatting, I'd love to be able to bring in the text as formatted. There is a way to move formatted text between these apps using the clipboard, but I'd like to do the data transfer without the need to invoke the Notes UI (back-end processing is normally much faster and less prone to user induced uhhh modifications).

    In the code below, you can see that I'm just replacing bookmarks with unformatted text from 'body' field in Notes mail.

    I've searched here, MS, and the Notes forum with no success.

    If I have a handle on a rich text object in Notes, is there a VBA method that lets me place that object at a specified place in a Word doc?

    Thanks in advance for any help.

    Doug

    Code:

    Sub Initialize

    'Original code posted by Darren Summerfield - LDD posting

    Dim s As New NotesSession
    Dim db As NotesDatabase
    Dim collection As NotesDocumentCollection
    Dim doc As NotesDocument
    Dim count As Integer
    Dim rtitem As Variant
    Dim plainText As String

    Set db = s.CurrentDatabase
    Set collection = db.AllDocuments

    count = collection.Count
    Set WordApp = CreateObject("Word.Application")
    WordApp.Visible = True

    For x = 1 To count

    Set doc = collection.GetNthDocument(x)
    If doc.Form(0) = "Main" Then Goto GetNext

    WordApp.Documents.Add("c:EMail.dot") ' contains a set of bookmarks that are used as placekeepers for specific field data.

    Set rtitem = doc.GetFirstItem( "Body" ) ' this line grabs the body field in the Notes email.
    plainText = rtitem.GetFormattedText( False, 0 ) ' converts RT to plain text
    WordApp.ActiveDocument.Bookmarks("Body").Select
    ' WordApp.Selection.TypeText(doc.body(0)) ' Note: if I use this line there's an error as 'body(0) is RT and the TypeText method fails
    WordApp.Selection.TypeText(plainText) ' this works but loose the formatting.
    'etc etc

    WordApp.Activedocument.SaveAs("c:emailemail" & Cstr(x) & ".DOC")
    WordApp.ActiveDocument.Close
    GetNext:
    Next x
    WordApp.Application.Quit

    End Sub

  2. #2
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: RichText into Word via OLE (Word 2000)

    It's that assignment into the string variable "plainText" what does it.

    If you can assign the rtitem to an object that supports RTF you'd have it. How about adding a bookmark with preserverformatting:=True?

    Or what about using the RichTextControl on a hidden form?

    Or maybe you could create an Autotext entry then insert that autotext at the bookmark.

    Just some ideas to explore.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  3. #3
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: RichText into Word via OLE (Word 2000)

    There is a property of a Selection or Range object called FormattedText. I don't know exactly how it differs from just Text, but maybe you can collapse your selection (or define a range) and then set Selection.FormattedText (or Range.FormattedText) = your rich text from Notes?

  4. #4
    New Lounger
    Join Date
    Aug 2002
    Location
    New Hampshire, USA
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: RichText into Word via OLE (Word 2000)

    I like the sound of this idea, unfortunately it doesn't seem to be working.

    Set rtitem = doc.GetFirstItem( "Body" )
    WordApp.ActiveDocument.Bookmarks("Body").Select
    WordApp.Selection.FormattedText = doc.body(0)
    OR
    WordApp.Selection.FormattedText(doc.body(0))
    OR
    WordApp.Selection.FormattedText(rtitem)

    All result in either an error 'Variant does not contain a container' - which usually means that the property or method attempted doesn't exist for the OLE object, in this case the 'selection.forattedtext' or my Notes client crashes when it hits the line. I just love OLE!

    I did not include any code to collapse the bookmark so I need to work out the syntax and try it again with a bookmark and a range just to see what happens.

    Thanks so very much for the reply. I'll let you know how this turns out.

    Doug

  5. #5
    New Lounger
    Join Date
    Aug 2002
    Location
    New Hampshire, USA
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: RichText into Word via OLE (Word 2000)

    Kevin,

    Thank you for your reply. Given that I'm not (yet?) a Word macro guru, I'm going to have to do a lot of digging to work through your suggestions. I haven't worked with RTControls or AutoText and need to figure out the preserveformatting thing. I'll play with these ideas and let you know what happens.

    Thanks again.

    Doug

Posting Permissions

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