Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Word Automation: Write RTF text without going through clipboard

I am trying to replace the current selection in Word (2003/2007) by some RTF string stored in a variable.

Here is the current code:

Clipboard.SetText(strRTFString, TextDataFormat.Rtf)
oWord.ActiveDocument.ActiveWindow.Selection.PasteAndFormat(0)

Is there any way to do the same thing without going through the clipboard. Or is there any way to push the clipboard data to a safe place and restore it after?

like image 892
Vincent Avatar asked Aug 22 '08 13:08

Vincent


1 Answers

Put the RTF in a file instead of the clipboard, then insert from the file, e.g.

Selection.InsertFile FileName:="myfile.rtf", Range :="", _ ConfirmConversions:=False, Link:=False, Attachment:=False

like image 96
Joel Spolsky Avatar answered Sep 27 '22 19:09

Joel Spolsky