---
title: "Extract text from opened Microsoft Word document"  
description: "Extract text from opened Microsoft Word document"  
author: "Mark Devid"  
published: 2013-12-23  
updated: 2013-12-23  
canonical: https://www.mindstick.com/forum/1830/extract-text-from-opened-microsoft-word-document  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# Extract text from opened Microsoft Word document

I need to [extract text](https://www.mindstick.com/interview/34137/how-do-you-extract-text-content-from-a-pdf-or-docx-file-in-c-sharp) (using C#, VS2012) from opened [word](https://www.mindstick.com/forum/305/read-word-file) [document](https://www.mindstick.com/articles/328642/what-to-consider-while-choosing-a-software-documentation-tool). I keep receiving an [error](https://yourviews.mindstick.com/view/88527/fixing-quickbooks-error-4120-reinstalling-vs-repairing) that '[cannot access](https://www.mindstick.com/forum/33726/inside-onclicklistener-i-cannot-access-a-lot-of-things-how-to-approach) [file](https://www.mindstick.com/articles/59/encrypting-and-decrypting-files-using-c-sharp), because it is being used by another [process](https://yourviews.mindstick.com/story/1525/7-important-factors-that-may-affect-the-learning-process)'. Is there any work around this? So I can extract text programmatically when document is opened in [Microsoft](https://www.mindstick.com/articles/12301/microsoft-is-trying-to-kill-passwords) Word?

## Replies

### Reply by Pravesh Singh

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)            {               
Console.WriteLine(word.Text);            }        }    }}
```

Remember to reference the Word Interop assembly.


---

Original Source: https://www.mindstick.com/forum/1830/extract-text-from-opened-microsoft-word-document

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
