Unclear on Application.ActiveDocument.Close

S

scw-tzg

VSTO app-level Add-in for Word 2007.

At some point, I have 1 open Word doc. I hit Word's 'X' button.

I have an Application_DocumentBeforeSave event handler to intercept saving
the document (if it had unsaved content). I save the document to my database
then I go through my "Close" then "Open" routine which I always do after
saving (I don't know at this point that user wants to exit. The exit event
wouldn't fire until later.)

So for "Close" I have C# code in ThisAddIn.cs like this:

if (Application.ActiveDocument == thisSelector.GetDocument)
{
object doNotSaveChanges = Word.WdSaveOptions.wdDoNotSaveChanges;
Word._Document document = Application.ActiveDocument;
document.Close(ref doNotSaveChanges, ref oMissing, ref oMissing);
}

This seems to execute okay. After this, I would expect
Application.Documents collection to contain 0 items, but that is not the
case; it still shows 1 item (which is the same document).

What am i missing? Why is there still a document there?

It causes me a problem because I get to may open code and I compare what I
want to open with what is in Application.Documents and I throw up a message
that "document is already open". After this Word does exit as desired, but I
hate to confuse my user with the already open message.

Susan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top