none
place cursor after what i just inserted RRS feed

  • Question

  • In my document level customization i have made functionallity to save document snippets as wordML, those snippets can then also be inserted.
    After inserting a WordML snippet i would like cursor to be placed after inserted snippet.
    i have made following method : 
            public static void InsertFragment(string path)
            {
                object missing = Type.Missing;
                object collapseEnd = Word.WdCollapseDirection.wdCollapseEnd;
                Selection theSelection = Globals.ThisDocument.Application.Selection;
                theSelection.InsertXML(proxy.getWordXMLSnippet(path), ref missing);
                theSelection.Collapse(ref collapseEnd);
                theSelection.Range.Select();
                theSelection.Range.InsertAfter(Environment.NewLine);
            }
    
    After this the cursor is placed just before inserted.
    any ideas ?


    • Edited by flinkemike1 Thursday, November 3, 2011 12:21 PM
    Thursday, November 3, 2011 11:27 AM

All replies

  • You could create a range at the start of the selection, and insert it there.

     

    Word.Range rangeInsert = Globals.ThisDocument.Content;

    rangeInsert.SetRange(theSelection.Start, theSelection.Start);

    rangeInsert.InsertXML(proxy.getWordXMLSnippet(path), ref missing);

    theSelection.SetRange(rangeInsert.End, rangeInsert.End);

     

    You may not need that the last line I've written. Another option would be to get the number of characters in the string you're inserting, and advance the selection by that amount.



    • Edited by JosephFox Thursday, November 3, 2011 9:41 PM syntax mistakes
    Thursday, November 3, 2011 2:30 PM
  • I tried your sample and it did not work, cursor is still in the top of inserted.

    As for your second solution, i dont think it will work, as the inserted is a xml string, and the WordML fragment can contain tables, pictures ...

     


    • Edited by flinkemike1 Monday, November 7, 2011 1:55 PM
    Monday, November 7, 2011 1:53 PM
  • Hi flinkemike1,

     

    Thanks for posting in the MSDN Forum.

     

    Would you please tell me what the instance of “proxy”?

     

    Have a good day,

     

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, November 8, 2011 9:20 AM
    Moderator
  • proxy is a webServiceReference. method just returns a WordML fragment as string
    Tuesday, November 8, 2011 10:37 AM