Extract RTF text from word without clipborad function?????

R

Rama

Hi All,
I'm trying to extract RTF text from a given word document and I'm
using clipboard functionality to get RTF text which is as follows. I'm using
..NET technology. I dont mind accepting VB6\VBA solution.

Dim data As IDataObject
oParagragh.Range.CopyAsPicture()
data = Clipboard.GetDataObject()
If Not data Is Nothing AndAlso _
data.GetDataPresent("Rich Text Format")
Then
strParagraphText = data.GetData("Rich
Text Format", True)
End If


As it intereferes with user copy\paste functionality I just want to findout
whether there are any other possible ways to extract RTF text without using
clipboard logic.
 
Y

yves

Hi All,
I'm trying to extract RTF text from a given word document and I'm
using clipboard functionality to get RTF text which is as follows. I'm using
.NET technology. I dont mind accepting VB6\VBA solution.

Dim data As IDataObject
oParagragh.Range.CopyAsPicture()
data = Clipboard.GetDataObject()
If Not data Is Nothing AndAlso _
data.GetDataPresent("Rich Text Format")
Then
strParagraphText = data.GetData("Rich
Text Format", True)
End If

As it intereferes with user copy\paste functionality I just want to findout
whether there are any other possible ways to extract RTF text without using
clipboard logic.

Hi Rama,

I would have Word transfer the formatted currently selected text into
a brand new document (without the clipboard), then have Word save it
as an RTF file, then open that RTF file into a string variable and
here we are.

Dim Object1 as Selection, T as String, RTF as String

'1. transfer the currently selected text to a new document without the
clipboard:

Set Object1 = Selection
Documents.Add
Selection.FormattedText = Object1.FormattedText

'2. Save new doc as RTF then close it

ActiveDocument.SaveAs "MyRTF.rtf", FileFormat:=wdFormatRTF
ActiveDocument.Close savechanges:=wdDoNotSaveChanges

'3. Grab the text in that file on disk:

Open "MyRTF.rtf" For Input As #1
Do While Not EOF(1)
Line Input #1, T
RTF = RTF + vbCr + T
Loop
Close #1

Kill "MyRTF.rtf"

= = = =

The RTF string variable contains your RTF text.
Does this help?

Yves Champollion

www.champollion.net
 
R

Rama

Hi Yves ,
Thanks for the reply. But I've to collect each and every
table's(20 x 70) cell value in RTF. in this case if I've more than 10 tables
then using the new instance logic would consume more time and is prone to
errors with many word instances open. Is there any other way to get the RTF.
for example if you look at "EnhMetaFileBits" property of office 2003 you can
easily capture pictures without any clipboard functionality.
 

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