Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / February 2006

Tip: Looking for answers? Try searching our database.

Copying RTF text with formatting

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mike - 01 Feb 2006 14:49 GMT
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
Dave Lett - 01 Feb 2006 15:51 GMT
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

> Have an RTF document with multiple text areas, each having some RTF formatting (bold, etc.). Each of these areas is contained in bookmark.
>
[quoted text clipped - 11 lines]
> Thanks,
> Mike
Mike - 02 Feb 2006 18:24 GMT
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

> Hi Mike,
>
[quoted text clipped - 27 lines]
>> Thanks,
>> Mike
Cindy M  -WordMVP- - 03 Feb 2006 17:52 GMT
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
[quoted text clipped - 5 lines]
> 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 :-)

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.