Home > DeveloperSection > Forums > Extract text from opened Microsoft Word document
Mark Devid
Mark Devid

Total Post:102

Posted on    December-23-2013 2:50 AM

 C# C# 

 1 Reply(s)
 887  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?

Pravesh Singh

Total Post:412

Posted on    December-23-2013 5:09 AM

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.

Don't want to miss updates? Please click the below button!

Follow MindStick