locked
How to select whole Word document? RRS feed

  • Question

  • Hello,

    in my MS Word Add-in I want to get whole document in string. I use this code:

    var charCount = Globals.ThisAddIn.Application.ActiveDocument.
                             Characters.Count;
                       
    Range rng = Globals.ThisAddIn.Application.ActiveDocument.
                        Range(0, charCount);
    text = rng.Text;

    But when I have for example 10 page in document, I haven't in variable 'text' all text but only part of the document.


    • Edited by Lenkita Wednesday, April 23, 2014 4:21 PM
    Wednesday, April 23, 2014 8:57 AM

Answers

  • You could use just:

    Range rng = Globals.ThisAddIn.Application.ActiveDocument.Range
    text = rng.Text


    Cheers
    Paul Edstein
    [MS MVP - Word]

    • Marked as answer by Lenkita Wednesday, April 23, 2014 1:25 PM
    Wednesday, April 23, 2014 9:44 AM