How to Programatically paste the clipboard contents to a word docu

How to Programatically paste the clipboard contents to a word docu

Post by dG9uX2N1b » Fri, 06 Jun 2008 21:15:01


Can anyone tell me how to Programatically paste the clipboard contents to a
word document using C#??

I am very new to programming (2 months). I am using Visual Studio.NET and
C#. I have made an Add-In for Word. One of the controls in my Add-In
Programatically copies a textbox (richTextBox1) contents to the Clipboard. I
used the following code:

Clipboard.SetText(richTextBox1.Text);

Then if I right click and select Paste the contents are pasted onto the Word
document.

However, I would like to Programatically paste the clipboard contents to
the word document? Can anyone tell me how to Programatically paste the
clipboard contents to a word document using C#??

I WAS able to instantiate a class using the "Interface" in the Object
Browser at Microsoft.Office.Interop.Word named "Selection" which contains a
method named "void Paste()".

However when I derived a class from it and then instantiated the class and
called the "Paste()" method it threw an error because there is no code in the
paste method. Can you give me an example of code that I can put into the past
method??

namespace WordAddIn2
{
class Class2:Selection //Implements the Interface found at
Microsoft.Office.Interop.Word.Selection
{
#region Selection Members...


public void Paste() // The paste method of the derived class
named Class2
{

throw new NotImplementedException();

..............................................................................................................................................................................................................


Class2 y = new Class2(); // In my Windows Form I have
instantiated Class2 so that I can use the Paste method
y.Paste();

................................................................................................................................................................................................................

When I run the program it throws an exception because I have not Implemented
the Paste Method. The problem is that I do not know how to Implement the
Paste method. Does anyone know how?????
 
 
 

How to Programatically paste the clipboard contents to a word docu

Post by Andrei Smo » Sat, 07 Jun 2008 22:01:47

The following method that handles the Click event of a toolbar button has
worked for me:
private void adxCommandBarButton1_Click(object sender)

{

WordApp.ActiveDocument.ActiveWindow.Selection.Paste();

}



Regards from Belarus (GMT+2),


Andrei Smolin
Add-in Express Team Leader
www.add-in-express.com