BeforeSave events cancel doesnt work

A

Arthur Fiedler

I'm using c# and im developing a com addin that needs the ability to cancel save's in word,excel,powerpoint, and visio... the problem is so far i tired with word and excel both programs when u set cancel = true in the even it doesnt cancel it!! ever! It does fire the event fine... I've tried various things including...

// add event
((Word.ApplicationEvents2_Event)wordApp).DocumentBeforeSave += new Word.ApplicationEvents2_DocumentBeforeSaveEventHandler(Word_BeforeSaveDocument);

// event fired
public void Word_BeforeSaveDocument(Word.Document wd, ref bool SaveAsUI, ref bool Cancel)
{
MessageBox.Show("You must first do ... to the document.");
//following doesnt work
Cancel = true;
}

i've also tried just marking the word document as saved and it seems not to try to save it then... but then inside excel i run into the problem where it saves it anyways! even if the .saved = true... i must stop this save event for my addin to work correctly... or i need some form of a workaround... anyone have anyideas?
 
B

Ben Engber

I am suffering from the exact same problem, except from the Excel
side. Does anyone have a solution to this?

Thanks,
Ben
 
A

Arthur Fiedler

well I havn't had any responses via email or on this newsgroup... but I decided to try this in VB.net and it seems to work just fine! its crazy why work in VB.net but not C# I've only tested it with word so far though. Other random problems I was having also seem to have disappered when using VB.net so I ported all my code to VB.net there is one issue that remains though... I'm using a popup with commandbuttons on it for my access to my program... when i click a button and use a form that you fill out if you show ANY dialog via form.showDialog() after the second time it crashes word... havn't found a workaround for this still... If anyone has ideas please post PLEASE!!! hehe

Arthur Fiedler

----- Ben Engber wrote: -----

I am suffering from the exact same problem, except from the Excel
side. Does anyone have a solution to this?

Thanks,
Ben
 
B

Ben Engber

Well, that makes absolutely no sense. I have far too much code to
port to VB.Net, but I did try porting just the event handling bit. No
difference, the events still get fired but can't cancel the save.

Anyone have ideas?


Arthur Fiedler said:
well I havn't had any responses via email or on this newsgroup...
but I decided to try this in VB.net and it seems to work just fine!
its crazy why work in VB.net but not C# I've only tested it with word
so far though. Other random problems I was having also seem to have
disappered when using VB.net so I ported all my code to VB.net there
is one issue that remains though... I'm using a popup with
commandbuttons on it for my access to my program... when i click a
button and use a form that you fill out if you show ANY dialog via
form.showDialog() after the second time it crashes word... havn't
found a workaround for this still... If anyone has ideas please post
PLEASE!!! hehe
 
S

Siew Moi Khor [MS]

Hi,
The following KB and post might help. Thanks.
http://support.microsoft.com/default.aspx?scid=kb;en-us;830519
http://groups.google.com/groups?hl=...+author:Torr&hl=en&lr=&ie=UTF-8&start=50&sa=N

Siew Moi
---
This posting is provided 'AS IS' with no warranties, and confers no rights.
Sample code subject to http://www.microsoft.com/info/cpyright.htm


Arthur Fiedler said:
I'm using c# and im developing a com addin that needs the ability to
cancel save's in word,excel,powerpoint, and visio... the problem is so far i
tired with word and excel both programs when u set cancel = true in the even
it doesnt cancel it!! ever! It does fire the event fine... I've tried
various things including...
// add event
((Word.ApplicationEvents2_Event)wordApp).DocumentBeforeSave += new Word.ApplicationEvents2_DocumentBeforeSaveEventHandler(Word_BeforeSaveDocume
nt);

// event fired
public void Word_BeforeSaveDocument(Word.Document wd, ref bool SaveAsUI, ref bool Cancel)
{
MessageBox.Show("You must first do ... to the document.");
//following doesnt work
Cancel = true;
}

i've also tried just marking the word document as saved and it seems not
to try to save it then... but then inside excel i run into the problem where
it saves it anyways! even if the .saved = true... i must stop this save
event for my addin to work correctly... or i need some form of a
workaround... anyone have anyideas?
 

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