This worked for me on Windows 7 and Word 2007:
public static void pasteHTML(this Range range, string html) { Clipboard.SetData( "HTML Format", string.Format("Version:0.9\nStartHTML:80\nEndHTML:{0,8}\nStart" + "Fragment:80\nEndFragment:{0,8}\n", 80 + html.Length) + html + "<"); range.Paste(); }
Example usage: range.pasteHTML("a<b>b</b>c");
Probably a more reliable way without using the clipboard is to save the HTML fragment in a file and use InsertFile . Sort of:
public static void insertHTML(this Range range, string html) { string path = System.IO.Path.GetTempFileName(); System.IO.File.WriteAllText(path, "<html>" + html);
source share