2

I have a VSTO Add-in in which I insert some formatted text into Selection.Range. Text is provided in Open XML format and is inserted to the document with InsertXML method:

using (var selection = _application.Selection)
{
    var range = selection.Range;
    range.Collapse(WdCollapseDirection.wdCollapseEnd);
    range.InsertXML(xml);
}

This works fine if the cursor is in wdMainTextStory. However, if I place it in a footnote, it does not work. It doesn't throw any error, but the text is just not inserted at all. I tried to watch range.Text and range.XML and it appears that they stay the same.

I tried to put the plain text by:

range.Text = "TEST";

And it worked.

Is there a way to put an XML into footnote's range? Am I doing something wrong here?

aurel
  • 1,117
  • 2
  • 11
  • 24
  • In a quick test (using VBA) it worked fine for me: `Set rng = ActiveDocument.Footnotes(1).Range : sOOXML = Selection.WordOpenXML : rng.InsertXML sOOXML` Perhaps you're trying to write something to the footnote that's not accepted in a footnote? Or the selection in the footnote is invalid in some way? Or is there some kind of protection in-force? – Cindy Meister Mar 12 '18 at 14:23
  • @CindyMeister could you please paste somewhere for me the xml string that you are inserting with success? I'll try it in my scenario so I'll know if the problem is with my xml or something else. – aurel Mar 12 '18 at 14:27
  • I almost asked you the same thing, but WordOpenXML is so verbose that it doesn't make much sense. What I did was to select some "plain text" in the document body, pick that up as WordOpenXML (since I know it to be valid) and insert that. – Cindy Meister Mar 12 '18 at 15:25
  • Yeah, but that's exacly what I'm doing :) And it works when I put these xml in main document range, it fails only in footnotes. So I guess my problem is somewhere else... – aurel Mar 14 '18 at 08:57

0 Answers0