Extract text from a word-document in rtf-format without using the clipboard

C

Christoph Hilmes

Hi NG,

i have an application using vb and word. I control word from within my
vb-application using vba. At one point i extract the text of a document in
rtf format (with all the rtf-commands) and put it into a string-variable.
Then i replace parts of the text using a string-search-and-replace-
algorithm. Afterwards i paste the text back into the word-document so that
the formatting is not lost. To achieve that i use the windows-clipboard.

To get the text out of the document:

Select_Text pos_beginn, pos_end
Clipboard.Clear
wordobj.Selection.Cut
text = Clipboard.GetText(vbCFRTF)

To paste it back into the document

Clipboard.Clear
Clipboard.SetText "{" & text_ein & "}", vbCFRTF
Select_Text pos_beginn, pos_end
wordobj.Selection.Range.Paste

That works pretty well on most systems. But with certain configurations
(most of all terminal-server-emulations) i got problems using the
clipboard. Therefore i search for another solution for my problem without
using the clipboard.

Can anybody help me here?

Thanks in advance.

Christoph
VB 6
Word 2000
 
K

Klaus Linke

Hi Christoph,

You could try to use WordML instead of RTF.

The two methods you need for that in a small sample:
Selection.Range.InsertXML(ActiveDocument.Paragraphs(1).Range.XML)

The hard parts are ignoring all the stuff that's in the WordML but doesn't really interest you, and keeping the XML well-formed and valid in your search-and-replace mangling.

Regards,
Klaus
 

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