Extract text from opened Microsoft Word document

Total Post:102


 1300  View(s)
Rate this:

I need to extract text (using C#, VS2012) from opened word document. I keep receiving an error that 'cannot access file, because it is being used by another process'. Is there any work around this? So I can extract text programmatically when document is opened in Microsoft Word?

  1. Re: Extract text from opened Microsoft Word document

    Hi Mark,

    If you cannot open the document programmatically, I would connect to the running instance of Word, get a handle to the document, and ask for the text in it. Like this:

    using System;
    using Microsoft.Office.Interop.Word;
    namespace ConsoleApplication12
        class Program
            static void Main(string[] args)
                var wordApp =(Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Word.Application");
                var words = wordApp.ActiveDocument.Words;
                foreach (Range word in words)

    Remember to reference the Word Interop assembly.

      Modified On Apr-04-2018 12:50:18 AM


Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.