Results 1 to 4 of 4
  1. #1
    3 Star Lounger
    Join Date
    Nov 2002
    Posts
    387
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Creating and inserting text into a word Instance (2000 - 2003)

    I want to create an empty instance of a Word Document and then insert RTF formated text into it and save it via VB 6 code (COM object). No problem create a Word instance using " Set example = CreateObject("Word.Application")"

    but from that point I am not sure what to do and can't find examples other than insert text into ranges, tables and in my case I am inserting RTF text into the instance.

  2. #2
    3 Star Lounger
    Join Date
    Nov 2002
    Posts
    387
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Creating and inserting text into a word Instance (2000 - 2003)

    Let me explain further, I can create the word instance and add text using:
    example.Documents.Add ,,
    ' Add some text.
    example.Selection.TypeText = "This is some text."
    but I am adding text that is RTF, i.e. it contains not only the reading text but the entire RTF for formatting, etc. and I want to be able to make it visible. What I am getting when I make the word instance visible after inserting the RTF text is the entire RTF text (including formatting instructions, etc). How do I avoid that other than saving the file first as a RTF and then reopening?

  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: Creating and inserting text into a word Instan

    Word's RTF converter definitely kicks in when you open the document, but perhaps it will kick in if you use Paste Special - Rich Text? I haven't tried it, but from VB6 you have the ability to place the RTF "code" on the clipboard using Windows API calls so it might be worth exploring.

  4. #4
    3 Star Lounger
    Join Date
    Nov 2002
    Posts
    387
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Creating and inserting text into a word Instan

    Thanks. The paste special doesn't work, only works if the RTF is a text file or of course RTF. The problem is I have a number of seperate RTF files that I have placed into an XML file instead of seperate files. A XML node is now what each file was. I search thru all of the nodes for a key word and if the key word exists then teh contents of that node (the RTF) is added toa string. When finished I save the str as a text file and then open the text file with Word. For many reason it would be better if I could just place the completed string directly into an open Word document instance rather than first saving the text file and then opening the text file with Word.

Posting Permissions

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