Wednesday, 14 August 2013

BookMark.PasteSpecial method Command Failed Error

BookMark.PasteSpecial method Command Failed Error

I want to open word document with html content(in C#) but I take "Command
Filed" error on the PasteSpecial method. How can I fix this?
Microsoft.Office.Interop.Word.Application app = new
Microsoft.Office.Interop.Word.Application();
app.Visible = true;
object template = Missing.Value;
object newTemplate = Missing.Value;
object documentType = Missing.Value;
object visible = true;
object missing = Missing.Value;
object DataType =
Microsoft.Office.Interop.Word.WdNewDocumentType.wdNewWebPage;
_Document doc = app.Documents.Add(ref template,
ref newTemplate,
ref DataType,
ref visible);
object bookmark = "entry";
object start = 0;
object end = 0;
object rng = doc.Range(ref start, ref end);
doc.Bookmarks.Add("entry", ref rng);
int b = doc.Bookmarks.Count;
Microsoft.Office.Interop.Word.Range rgBookMark =
doc.Bookmarks.get_Item(ref bookmark).Range;
DataObject cbObj = new DataObject();
cbObj.SetData(DataFormats.Html, "<html><body>HTML
CONTENT</body></html>");
Clipboard.SetDataObject(cbObj, true);
object datatype =
Microsoft.Office.Interop.Word.WdPasteDataType.wdPasteHTML;
rgBookMark.PasteSpecial(ref missing, ref missing, ref
missing,
ref missing, ref datatype, ref missing, ref missing);

No comments:

Post a Comment