Results 1 to 8 of 8
  1. #1
    Lounger
    Join Date
    Aug 2003
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Rich Text data (word 2000 )

    I have a table which has rich text data in it, does anyone know what i need to do to display this information in a word document?
    Thanks

  2. #2
    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: Rich Text data (word 2000 )

    What is the source? If it's another Word document, copy and paste (using either a Range or Selection object) would be a good way to ensure that the formatting carries over. Well, that and making sure that the relevant styles in the destination document match those used in the table.

  3. #3
    Lounger
    Join Date
    Aug 2003
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Rich Text data (word 2000 )

    No, the data is in a .db table not in a word document. When i select the information using a SELECT statement and put the information in a bookmark, all the tagged information also gets copied in the bookmark. <img src=/S/bwaaah.gif border=0 alt=bwaaah width=123 height=15>

  4. #4
    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: Rich Text data (word 2000 )

    Okay, I'm not sure how to program this, but take a look at Edit>Paste Special and see if it understands the information to be in rich text format. It's a huge hassle having to feed strings through the clipboard, but compared with learning how to create an RTF document from scratch, maybe it's not that huge. (Someone posted some "I'm creating RTF documents" code earlier this year, but I can't recall who or in what context. It sounded like hard work...)

  5. #5
    Bronze Lounger
    Join Date
    Nov 2001
    Location
    Arlington, Virginia, USA
    Posts
    1,394
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Re: Rich Text data (word 2000 )

    I don't know how this information is stored in the db table, so don't know if this will work. If you save formatted text in Word as an .RTF file, then open file in a text editor such as Notepad, and then save as a text file in Notepad, the resulting text file includes all the RTF encoding verbatim & looks something like this:

    li0ri0widctlparaspalphaaspnumfaautoadjustrig
    htrin0lin0itap0
    fs20lang1033langfe1033cgridlangnp1033langfenp
    1033 {bf2cf2
    par }{f1 Caption: Microsoft Visual Basic -
    HwndStuff [running] - [modHwndStuff (Code)]
    (etc)

    If you try to copy this text into a Word document, whether using Paste or Paste Special, the text is simply copied verbatim, as shown above, with no formatting applied. However, if you use Word's Insert - File... menu command and select the text file with the .RTF encoding descriptions, the resulting document displays correct formatting, without the RTF encoding visible, just the literal text with formatting applied. So you would probably have the save the data in db table as a text file (a simple task in most db programs), then use VBA to insert file in Word doc. Simple macro:

    Sub InsertFileRTF()
    '
    ' InsertFileRTF Macro
    ' Macro recorded 11/21/2003 by MARK D
    '
    Selection.InsertFile FileName:="Hwnd.txt", Range:="",
    ConfirmConversions:= False, Link:=False, Attachment:=False
    End Sub

    Above code worked OK in simple test.

    HTH

  6. #6
    Lounger
    Join Date
    Aug 2003
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Rich Text data (word 2000 )

    Thanks this works only if my data is stored in a file. my data is stored in a table in a database. The table has 2 columns: ln_num, cmt. i get the comment into a local variable.. How do i proceed from there ?

    Thanks for the help...

  7. #7
    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: Rich Text data (word 2000 )

    Well, as Mark said, you'd first have to write the data to a file. Based on a little experimentation, you can't just pop the field contents into a file and expect Word to recognize it as RTF. You're going to have to precede it with some headers. Using WordPad generates much simpler header than Word. Here's a sample for a document that consists of nothing other than:

    Line 1
    Line 2

    on the screen. Its RTF code is:

    {rtf1ansiansicpg1252deff0deflang1033deflangfe1033{ fonttbl{f0fswissfcharset0 Arial;}}
    {*generator Msftedit 5.41.15.1503;}viewkind4uc1pardf0fs20 Line 1par
    Line 2par
    }

    Efforts to simplify this were met with nothing being inserted, so blind experimentation probably won't lead to further progress. Instead, you could look up the RTF spec on the web and see if there's any other way to get this going more quickly. Until then, hope this helps.

  8. #8
    Bronze Lounger
    Join Date
    Nov 2001
    Location
    Arlington, Virginia, USA
    Posts
    1,394
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Re: Rich Text data (word 2000 )

    You did not specify what database application the data is stored in. Also, are you trying to insert the data into an existing Word document, with predefined bookmarks? When exporting data to Word from a database, I normally use a pre-defined Word template as basis for the new document, with predefined bookmarks and/or formfields that determine where the data will be inserted in document. As noted previously, you would probably have to save the data with formatting instructions in a text file (from the db), then in Word, insert the text file at specified location in document. Here is simple example, based on recorded macro (the recorded code was cleaned up & reduced to a single instruction):

    Sub GoToBookmarkAndInsertTextFile()
    '
    ' GoToBookmarkAndInsertTextFile Macro
    ' Macro recorded & modified 11/22/2003 by MARK D

    ActiveDocument.Bookmarks("Bookmark1").Range.Insert File _
    FileName:="C:AccessHwnd.txt", _
    Range:="", ConfirmConversions:=False, _
    Link:=False, Attachment:=False

    End Sub

    If automating this from another app in VBA you'd use an object variable referring to a Word Document object in place of ActiveDocument. If the bookmarks are being generated dynamically, once bookmark defined and added to doc's Bookmarks collection, you could use instruction like that above to insert the text file at specified bookmark. The InsertFile method applies to both a Range object and a Selection object.

    Without knowing what db program you are using cannot provide more specifics on how to get the data into a text file. Most db programs allow you to write data to a text file. In Access, for example, this is a simple task. Not sure why or how this data is saved in a db file. I never felt compelled to save formatting instructions in a db file, nor to struggle with Rich Text controls in a db app, that's why they invented stuff like Rich Text , and HTML, Style Sheets, etc.

    HTH

Posting Permissions

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