How can I toggle visibility of a word document at the document level? RRS feed

  • Question

  • I have a program Using .NET 2.0 that automates the filling out of Forms (MS Word Documents.) It opens it's own instance of Word (Currently Word 2003) to do this. When the user prints the documents they are immediately closed. Except any other documents the user has opened during this process.  Problem is if they choose to create more forms I don't want to display the new forms until the find/replace process has completed and the document is ready. All of the solutions I've seen online deal with toggling the Visibilty of the Word Application itself which means hiding the users other document(s).  So how can I hide/show individual documents from the documents collection in Word?

    Any help would be much appreciated.

    P.S. I apologize if this is the wrong forum for this post, I was unsure of the proper place.


    UPDATE: I figured it out. The Document Class has a Windows Collection. It's not very clean but it works.

    Code Example below for those who care:

      foreach ( Window win in myDocument.Windows )
    { win.Visible = false; }

    Apparently the way the Document object model is you can actually have multiple windows open for the same document. This simple loops sets them all invisible and then I just re-display them with a similar loop when I'm done with the files.

    • Edited by Raystorm Saturday, May 15, 2010 12:53 AM solved my problem
    • Moved by Harry Zhu Wednesday, May 19, 2010 7:50 AM (From:Visual C# General)
    Friday, May 14, 2010 9:32 PM

All replies