0

I am using this code to get and minimize all open Word documents.

Word.Application wordApp = new Word.Application();
Word.Documents docs = wordApp.Documents;

wordApp.ScreenUpdating = true;
wordApp.WindowState = Word.WdWindowState.wdWindowStateMinimize;

But documents list is empty despite the fact that I have open Word 2010 documents in Windows 7. Also minimization is not working.

How can I get and minimize all open Word documents?

tshepang
  • 12,111
  • 21
  • 91
  • 136
Piotr
  • 1

1 Answers1

1

new Word.Application() will always create a new instance of Word.

to connect to an existing instance, you can use

Word.Application wordApp = (Word.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Word.Application");

(this is similar to the VB/VBA "GetObject" function).

Then you should be able to access your documents.