This is weird - change document but no event

D

David Thielen

Hi;

Open Word - it has a new document. Then click file and one of the MRU files.
It opens that document in that instance of word discarding the new document.

However, as near as I can tell, there is no event to let you know this. I
figured you should get a DocumentBeforeClose event.

The workaround is that on the DocumentOpen event for the opened document -
the old Document is gone from Application.Documents.
 
P

Peter Huang [MSFT]

Hi

Based on my research, I think this is by design.
Word did not consider the first opened blank untouched document1 as a
common document. It will be replaced automatically by the following opened
document.
But if we has do any change to it, when the second one is opened, the first
one will not closed. Now we will have two documents opened.
Here is my test log for your reference.

00000000 0.00000000 [884] *** OnConnection ***
00000001 0.00827033 [884] Microsoft Word On Connection
00000002 0.00832807 [884] ConnectMode = 1
00000003 0.00837752 [884] Custom(1) = 1
00000004 0.00842543 [884] App Version = 11.0
00000005 0.00871286 [884] gbIsValidLangSetting = True
00000006 0.00966707 [884] gbBootLoad = True
00000007 0.00976192 [884] Microsoft Word On AddInsUpdate
00000008 0.06150708 [884] Microsoft Word On StartupComplete
00000009 0.42658977 [884] wdApp_DocumentChange
00000010 9.82463469 [884] wdApp_DocumentChange
00000011 9.88214593 [884] wdApp_DocumentOpen
00000012 20.08147005 [884] wdApp_DocumentChange
00000013 20.18267184 [884] wdApp_DocumentOpen
00000014 28.86236128 [884] wdApp_DocumentChange
00000015 28.86335233 [884] wdApp_DocumentOpen
00000016 37.19234279 [884] wdApp_DocumentBeforeClose
00000017 37.51692606 [884] wdApp_DocumentChange
00000018 39.72333961 [884] wdApp_DocumentBeforeClose
00000019 39.79641105 [884] wdApp_DocumentChange
00000020 41.68261428 [884] wdApp_DocumentBeforeClose
00000021 41.72835932 [884] wdApp_DocumentChange
00000022 41.72997779 [884] Microsoft Word On BeginShutdown
00000023 41.73062051 [884] *** OnDisconnection ***
00000024 41.73078799 [884] Microsoft Word On Disconnection
00000025 41.73085441 [884] RemoveMode = 0
00000026 41.87126952 [884] DLL_PROCESS_DETACH in MSGR3SC.DLL

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
D

David Thielen

Hi;

I can see the argument for not having it too. The problem is that it is a
new Document object so the old Document obbject goes away - but there is no
event to tell you that.

What I did was just walk the Application.Documents collection on the open as
by that time the old one is gone and I can find it that way.

But I do think there should be a close event on the first document...
 
P

Peter Huang [MSFT]

Hi

I have some confusion about your scenario.
Based on my test, if we have a word document opened already, if we create a
new blank document, then there will be two document windows.
And if we now open a named document, then there will be three document.
That is to say, we now consider the new document as a new document object.
But if we call winword.exe to create a word process, it will automatically
open a blank document, this one can be considered as a shadow document.
Because at this time, word did not know what will do you next.
If you wants to create a new document, then you just modify the current one
and save it.
If you wants to open a named document , then we do not need to close or
save the blank document first, because it is not our goal to open a
existing document but save or close a unnecessary one first.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
D

David Thielen

My point is that the "shadow document" did provide a NewDocument event - but
no CloseDocument event. So based on events the document was created and never
closed.

As I said, I have a work-around implemented. But unmatched events are
usually bad.
 
P

Peter Huang [MSFT]

Hi David,

Thanks for your feedback, I will report that.
Also as I said before, if we open winword.exe and close it immediately, it
will not create any document on the disk just as we have not do that before.
You may also try the mswish program as I provide in another thread, that
use the Email/FAX/Mail approach.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 

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