Copying RTF text with formatting

M

Mike

Have an RTF document with multiple text areas, each having some RTF formatting (bold, etc.). Each of these areas is contained in bookmark.

I've written a VBA module to loop through the bookmarks and copy the contents to memo fields in an Access database as rich text.

The only problem I am having is that the formatting (forecolor, bolding) does not come across. (I subsequently fetch the field from Access and display it in a rich text box in another app.)


What I do to copy the pieces out of the original RTF doc is:

UserForm1.rtb.Text = ActiveDocument.Bookmarks(szBookMark).Range
fld.Value = UserForm1.rtb.TextRTF

Any suggestions on how to capture the formatting as well? I suppose that I could copy each section to a file and then save the file into the dB but I was hoping to avoid that.

Thanks,
Mike
 
D

Dave Lett

Hi Mike,

If UserForm1.rtb.Text and fld.Vale can take formatted text, then you can
try the following:


ActiveDocument.Bookmarks(szBookMark).Range.FormattedText


HTH,
Dave
 
M

Mike

Dave,

Thanks - I did try that initially - no luck.

Seems that setting the Text property of the control to the Bookmark Range
causes the RTF formatting to be lost. When I copy the TextRTF property of
the control to the database field - I'm just kidding myself ... it is in RTF
format but all the formatting has already been lost.

I've tried using the Clipboard/DataObject and I think it will work in NET as
the DataObject does support an RTF format. Word XP does not seem to unless I
save the Range object to a file and paste the rtf string from that file into
the dB.

Thanks again for your time,
Mike
 
C

Cindy M -WordMVP-

Hi Mike,
Seems that setting the Text property of the control to the Bookmark Range
causes the RTF formatting to be lost. When I copy the TextRTF property of
the control to the database field - I'm just kidding myself ... it is in RTF
format but all the formatting has already been lost.

I've tried using the Clipboard/DataObject and I think it will work in NET as
the DataObject does support an RTF format. Word XP does not seem to unless I
save the Range object to a file and paste the rtf string from that file into
the dB.
That's correct. Word requiers a conversion filter to place RTF into a document.
If you can get the data onto the Clipboard in RTF format, then it should paste
into Word the same way. Otherwise via a file is the only possibility.

A bookmark.Range.Text will only yield plain text. Bookmark.Range.FormattedText
will pick up the formatting, but as Word formatting, not RTF (as soon as you
open the document in Word, Word treats it as a Word document, no matter what
the original file format).

If we're talking Word 2003, Word's native XML might be an option for you...

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top