Access Violation in Word when calling ActiveDocument.Close()

Add-in Express™ Support Service
That's what is more important than anything else

Access Violation in Word when calling ActiveDocument.Close()
 
Hannes Koidl




Posts: 310
Joined: 2008-05-19
Hi Guys,

today i ran in exactly this Problem:

http://support.microsoft.com/kb/261158

It happens when you add an ContextMenu to Word, and in the ClickEvent you call:

wordApplication.ActiveDocument.Close(ref saveOption, ref originalFormat, ref omissing);

If this is the last Document you get the AccessViolation. I just updated my Office PIA's to the 2003 Version - but still without success.

Has someone an suggestion what i can do here?

Or if you have an better Idea how i can handle this one: I need to process the current Document into an DMS System. For this i need to read the File, thats why i need to close the current Document, read it with an FileReader, and then reopen it. I didnt found an way to save the ActiveDocument in an Temp Path - because when i call SaveAs() - the document gets the Active one?

thx
Hannes
Posted 12 Jul, 2009 16:32:29 Top
Andrei Smolin


Add-in Express team


Posts: 14140
Joined: 2006-05-11
Hi Hannes,

Try using the SendMessage method and OnSendMessage event of your add-in module. This allows executing this code line a) after a small delay and b) not in the Click event.

Regards from Belarus (GMT+2),

Andrei Smolin
Add-in Express Team Leader
Posted 13 Jul, 2009 13:13:38 Top
Hannes Koidl




Posts: 310
Joined: 2008-05-19
Hi Andrei,

thx for the good suggestion. Do you mean in the Click Event i to a SendMessage("MyMessage") and in the OnSendMessage i call my Code with the Close Method?

Do you know why this Problem still exists?

thx
Martin
Posted 13 Jul, 2009 13:38:00 Top
Andrei Smolin


Add-in Express team


Posts: 14140
Joined: 2006-05-11
Hi Martin,

Do you mean in the Click Event i to a SendMessage("MyMessage") and in the OnSendMessage i call my Code with the Close Method?


Yes, this way exactly.

Do you know why this Problem still exists?


I don't know. I suppose. They didn't expect someone closing the document from a context menu item.

Regards from Belarus (GMT+2),

Andrei Smolin
Add-in Express Team Leader
Posted 13 Jul, 2009 14:01:50 Top
Hannes Koidl




Posts: 310
Joined: 2008-05-19
I don't know. I suppose. They didn't expect someone closing the document from a context menu item.


Parhaps they should :) I just need to close it temporary to make a copy of the current Doc.

The SendMessage Trick did it Sergey - thx!
Posted 13 Jul, 2009 15:19:58 Top