keyongtech


  keyongtech > office.* > office.developer.com.add_ins

 #1  
02-04-10, 08:54 PM
David Thielen
Word.ApplicationClass..Documents.Count is 1 so I have a document. This
occurs when closing a 2nd copy of Word.

What can I test to see if there is an active document that does not
throw an exception?

thanks - dave

david@at-at-at
Windward Reports -- http://www.WindwardReports.com
me -- http://dave.thielen.com

Cubicle Wars - http://www.windwardreports.com/film.htm
 #2  
02-08-10, 10:40 AM
Colbert Zhou [MSFT]
Hi Dave,

This is strange. I do a lot of tests but cannot see the issue. In all of my
tests, the ActiveDocument always returns the COM object of the active
document. Even when I close an active document, another document becomes
active and fills the ActiveDocument property. So I guess this may related
to the calling context. In what codes, or event handles, you call the
ActiveDocument and get the error?

And is it possible to share with me a simplified reproduce sample and
detailed steps? After I can reproduce the issue, then I will do more
investigation in my side to see if we can come to a solution.


Best regards,
Ji Zhou
Microsoft Online Community Support
 #3  
02-08-10, 09:50 PM
David Thielen
Got a way to get it:
1) Open Word twice
2) Close document but leave word open with no document in the first
instance
3) Close the second instance of Word

You then will get an event where there is no ActiveDocument. This
makes sense as the one instance has no document in it. The problem is
that for a short period the Documents.Count is 1 but there is no
ActiveDocument.

thanks - dave


On Mon, 08 Feb 2010 10:40:49 GMT, colbertz
(Colbert Zhou [MSFT]) wrote:

>Hi Dave,
>
>This is strange. I do a lot of tests but cannot see the issue. In all of my
>tests, the ActiveDocument always returns the COM object of the active
>document. Even when I close an active document, another document becomes
>active and fills the ActiveDocument property. So I guess this may related
>to the calling context. In what codes, or event handles, you call the
>ActiveDocument and get the error?
>
>And is it possible to share with me a simplified reproduce sample and
>detailed steps? After I can reproduce the issue, then I will do more
>investigation in my side to see if we can come to a solution.
>>Best regards,

>Ji Zhou
>Microsoft Online Community Support



david@at-at-at
Windward Reports -- http://www.WindwardReports.com
me -- http://dave.thielen.com

Cubicle Wars - http://www.windwardreports.com/film.htm
 #4  
02-09-10, 02:58 PM
Colbert Zhou [MSFT]
I still cannot reproduce.

When I close the documents and leave Word without document opened, the
ActiveDocument is null, but the Documents.Count is always 0. So
ActiveDocument and Documents.Count are always consistent in my side.

I notice you mention,
"You then will get an event where there is no ActiveDocument. ".

What event you are exactly talking about? Could you please provide the code
context or a reproduce sample will help in this case.


Best regards,
Ji Zhou
Microsoft Online Community Support in Forum
 #5  
02-16-10, 10:00 PM
David Thielen
Hi;

I've just tried to do this - and can't. Somehow before I had a case
where I had 2 copies of Word running and one had no document. In that
case, when the instance of Word with no document was the active
application the call to ActiveDocument threw an exception.

I think I was checking when updating the ribbon menu. I think the
ribbon update was due to Word but might have been my calling update on
it on the event of closing the document.

This also occurs if you have one instance of Word running and it has
no docoument. But to handle that I check the Documents.Count property
first and if it's 0 then don't check ActiveDocument.

??? - thanks - dave


On Tue, 09 Feb 2010 14:58:10 GMT, colbertz
(Colbert Zhou [MSFT]) wrote:

>I still cannot reproduce.
>
>When I close the documents and leave Word without document opened, the
>ActiveDocument is null, but the Documents.Count is always 0. So
>ActiveDocument and Documents.Count are always consistent in my side.
>
>I notice you mention,
>"You then will get an event where there is no ActiveDocument. ".
>
>What event you are exactly talking about? Could you please provide the code
>context or a reproduce sample will help in this case.
>>Best regards,

>Ji Zhou
>Microsoft Online Community Support in Forum



david@at-at-at
Windward Reports -- http://www.WindwardReports.com
me -- http://dave.thielen.com

Cubicle Wars - http://www.windwardreports.com/film.htm
 #6  
02-22-10, 11:21 AM
Colbert Zhou [MSFT]
Hello Dave,

Sorry for following up late.

Yes, I can see ActiveDocument throws an exception if there is no document
opened in the Word. But I think that should be by designed because there is
exactly no active document opened. So the recommendded solution is before
every access to ActiveDocument, we check the Documents.Count to see if it
is 0.

I do a lot of tests in my side. In all of them, I find the ActiveDocument
and Documents.Count are consistent. That is to say,
1.When ActiveDocument throws exception, Documents.Count is 0
2.If Document.Count is 1 or bigger. I can use ActiveDocument correctly. No
exception is thrown.

So going back the original question, is it possible to provide a simplified
project that shows the problem as you described, "ActiveDocument throws
exception while Documents.Count is 1". If yes, it will help us to isolate
and investigate the issue. :-)

Have a nice day!

Best regards,
Ji Zhou
Microsoft Online Community Support
 #7  
02-22-10, 04:07 PM
David Thielen
Hi;

I've tried & tried and cannot re-create the situation. But I swear I
had it - two copies of Word open and the active one had no document..
When I hit it again I'll immediately write down how I made it happen
and post here.

thanks - dave


On Mon, 22 Feb 2010 11:21:03 GMT, colbertz
(Colbert Zhou [MSFT]) wrote:

[..]
>So going back the original question, is it possible to provide a simplified
>project that shows the problem as you described, "ActiveDocument throws
>exception while Documents.Count is 1". If yes, it will help us to isolate
>and investigate the issue. :-)
>
>Have a nice day!
>
>Best regards,
>Ji Zhou
>Microsoft Online Community Support



david@at-at-at
Windward Reports -- http://www.WindwardReports.com
me -- http://dave.thielen.com

Cubicle Wars - http://www.windwardreports.com/film.htm
 #8  
02-24-10, 12:19 PM
Colbert Zhou [MSFT]
Sure. After reproducing it, just post it here and I will follow up and try
my best to provide further help on this.

Have a nice day!


Best regards,
Ji Zhou - MSFT
Microsoft
 #9  
03-01-10, 05:32 PM
David Thielen
Hi;

I got it again, but only because of a bug in my code. Under normal
conditions it cannot happen. I've wrapped it in a try/catch and I
think that is good enough as this is so rare.

thanks - dave


On Wed, 24 Feb 2010 12:19:33 GMT, colbertz
(Colbert Zhou [MSFT]) wrote:

>Sure. After reproducing it, just post it here and I will follow up and try
>my best to provide further help on this.
>
>Have a nice day!
>>Best regards,

>Ji Zhou - MSFT
>Microsoft



david@at-at-at
Windward Reports -- http://www.WindwardReports.com
me -- http://dave.thielen.com

Cubicle Wars - http://www.windwardreports.com/film.htm
 #10  
03-02-10, 01:10 PM
Colbert Zhou [MSFT]
OK. Glad to hear it works as expected now. If you need more support on
this, just let me know. :-) Have a nice day!


Best regards,
Ji Zhou - MSFT
Microsoft Online Community Support
Similar Threads
new Word.ApplicationClass() (impersonation)

Hi, I have a problem with the MS-WORD Automation. I have done lots of things but couldn't find a solution for... When I write <identity impersonate="true"...

Word.ApplicationClass ProcessID

Hi, I'm launching Word within a .net c# application. At some point, i instantiate Word.ApplicationClass class and notice that this starts a new Word Process (you can view...

Replace all in Word.ApplicationClass

I created a solution using the Word.ApplicationClass where I want to open an existing Word document, find a certain string and replace all found instances of the string with...

cant get activedocument.Hyperlinks(1).Address throws 4198 command failed

Hi all, this is related to my last question about Hyperlinks containing Paragraph marks. eg: if (P) is a paragraph mark and both these lines have hyperlinks AND the (P) is...

Word.ApplicationClass

Hai, Has any one used Microsoft Office Word in C# Application. How can i combine two word files into a single word file using the Word.Application and Word.Document...


All times are GMT. The time now is 12:09 AM. | Privacy Policy