Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

RTF Files

Status
Not open for further replies.

VeryNewbie2004

Programmer
Sep 9, 2004
16
US
I am tring to convert a line of RTF code into it's text value.

Is there a way that anyone knows of doing this without using a RTF control on a form?

Thanks In Advance

 
Sure is

Before proceeding, though, it would be worth knowing why you want to avoid an RTF control (say with visible=false) on the form.
 
I was playing with stripping out the RTF codes recently, and found it MUCH easier to just drop the code into a hidden Rich Text Box as .TextRTF and read out the .Text value. If you want to see what you have to do, find the RTF format specs at wotsit.com, and you can see what you have to do to make it work from there.

Lee
 
No problem Strong

It's part of a class module that I envisage will be reused a good number of times so I don't think the hidden control is an option (unless you can think of a satisfactory way of intergrating it).

In this instance I am running a procedure which takes the text from a certain paragraphs within an RTF File and outputs the text only.

Currently this system works using Word, but it takes literally days to run over a file set. I can pull out the lines I want directly out the file quick enough, my problem is converting them to plain text.
 
Cheers Lee

Thats what I started doing this morning, then decided there had to be an easier way.

I suppose I could use a control to do this if I placed it on a new form which I don't show to keep it more re-usable. I just that would be a little bit of a hash even by my low standards.
 
No reason why a class can't have a hidden, unused form. However...

You'll be pleased to know that the RichTextBox OCX is one of (several) VB OCXs that don't actually need to be hosted on a form. You can add it as a Reference to you project rather than as a Component. It won't appear on the referneces list by default; you'll need to hit the Browse button, and then find and select RICHTX32.OCX in System32. Once that is done the following works fine:
Code:
    Dim myRTF As RichTextBox
    
    Set myRTF = New RichTextBox

    myRTF.TextRTF = "{\rtf1\ansi\ansicpg1252\deff0{\fonttbl{\f0\fnil\fcharset0 MS Sans Serif;}}\viewkind4\uc1\pard\lang2057\f0\fs17 Example\par }"
    Debug.Print myRTF.Text
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top