Richtext box

J

JGM

Greetings to all!

On Word XP, I have a userform that has a richtextbox. I am trying to use
either the standard richtx32.ocx or a freebie I have found on the Internet:
RTF2.ocx (by Lebans).

The result is the same... for testing purposes I used the following code to
insert the text from the richtextboxes in the current document:
Selection.TypeText RTF21.rtfText
Selection.TypeText vbCrLf
Selection.TypeText RichTextBox1.TextRTF

but what I get is:
{\rtf1\ansi\ansicpg1252\deff0\deflang3084{\fonttbl{\f0\fswiss\fprq2\fcharset
0 System;}}

{\*\generator Riched20 5.40.11.2210;}\viewkind4\uc1\pard\ul\b\f0\fs20 Sample
text in a RichTextBox\par





{\rtf1\ansi\ansicpg1252\deff0\deflang3084{\fonttbl{\f0\fswiss\fprq2\fcharset
0 System;}{\f1\fnil\fcharset0 Tahoma;}}

{\*\generator Riched20 5.40.11.2210;}\viewkind4\uc1\pard\b\f0\fs20 Sample
text in a RichTextBox\b0\f1\fs17

\par }¶


instead of
"Sample text in a RichTextBox" with various font/paragraph attributes.

How do I transfer the rich text code from the richrextbox to the document so
that they take effect? Is this possible or is a richtextbox for onscreen
work only?
What am I missing?

By the way, I prefer working with the Lebans'one because the user can do a
right-click and change all the attributes while in the typing text in the
richtextbox control. With the Microsoft one, I do not know how to achieve
the same result, but I can copy preformated text into it... and still obtain
ther same result.

Thanks.
 
J

JGM

HI there...

Don't like doing this...but have found a solution.

First, I tried through the clipboard but I could not get it to work.

So now, here is the code I use.

I anyone can see a potential problem or, even better, knows of an easier way
of doing this, please let me know!

_______________________________________
'Used in the CommandButton_Click code

Dim CurrentPara As Paragraph
Dim myRTFdoc As Document
Const RTFDocPathandName As String = _
"D:\FCI\Divers\myrtf.rtf"

Set CurrentPara = Selection.Paragraphs(1)

'On the userform,
'I have an invisible MS Windows RichTextBox control
'and a visible "Lebans" RichTextBox control
'I use Lebans because it has a nice way of formatting the content
'of the RichTextBox control by using only the right click
'but it does not have the SaveFile method available to the
'MS RichTextBox control
'It did have a Copy (to clipboard) method
'but I could not get it to work
'If someone knows how to format text in an MS RichTextBox control
'without having to add numerous buttons to the form,
'please let me know, I will be happy to simplify mycode
'and get rid of the extra RichTextBox control

RichTextBox1 = RTF21.rtfText

RichTextBox1.SaveFile RTFDocPathandName

Set myRTFdoc = Documents.Open(FileName:=RTFDocPathandName,
Visible:=False)

CurrentPara.Range.FormattedText = myRTFdoc.Content.FormattedText

myRTFdoc.Close

Set CurrentPara = Nothing
Set myRTFdoc = Nothing

Unload Me
_______________________________________
--

Thanks
_______________________________________
Jean-Guy Marcil
(e-mail address removed)

JGM said:
Greetings to all!
 

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