Hi,

Im trying to transfer some text from the richTextBox into an existing MS word template at a specific location.
I am able to transfer text to any location i like, but i want to retain the formatting of the text from the richTextBox.

Im trying to copy the text to the clipboard, and pasting it in Word, but its not working for some reason.

Microsoft.Office.Interop.Word.Selection sel = oWord.Selection;
Clipboard.Clear();                    
//richTextBox4.SelectAll();
Clipboard.SetDataObject(richTextBox4.Rtf, true);                        
                    
IDataObject data = Clipboard.GetDataObject();                    
sel.InsertBefore(data.GetData(DataFormats.Rtf).ToString());

Can anyone tell me how to fix this, or is there any other way to transfer a chunk of text from richTextBox to MS Word without loosing the formatting.
please note: i know i can directly save data from richTextBox to an rtf or doc file.. i want to insert the data in an existing template.

thanks!

Hello.
I was playing with your code. Here's what I've got:

// selecting some text in RichTextBox
...
Clipboard.SetText(richTextBox1.SelectedRtf, TextDataFormat.Rtf);
sel.Paste();

Hey thanks for that! It works!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.