2

I insert some dynamic text at a random position of a Word document and need the cursor to be sitting just at the end of this text afterwards (NOT end of document!). By now the cursor stays in the position it was before, which is at the beginning of the inserted text.

Not much useful code to show here I think ... I just copy some html into a file and insert it into the document:

          string tmp = AppDomain.CurrentDomain.BaseDirectory + "tmp.html";
          using (StreamWriter file = new StreamWriter(tmp))
          {
            file.Write(report, 0, report.Length);
          }

          var currentCursorPosition = Globals.ThisAddIn.Application.Selection.Range;
          currentCursorPosition.InsertFile(tmp);
DomMa
  • 153
  • 1
  • 11

1 Answers1

0

I suggest you to use Microsoft.Office.Interop.Word library. you can move cursor to the end of word document by it. use this: Move my cursor to the end of the Text in MsWord using C#?

itmanir
  • 167
  • 1
  • 3
  • 14
  • Doesn´t work for me, because my text could be inserted anywhere in a document, not just at the end. Forgot to mention this, I´ll add it to the question – DomMa Dec 17 '18 at 09:15