Cancelling the BeforeClose Event

  • Thread starter Thread starter Troy
  • Start date Start date
T

Troy

I am using .NET Tools for Office with Excel 2003 Beta.

There is a 'Cancel' flag in the BeforeClose event and if
it is assigned the value of 'True' it is supposed to stop
Excel for closing, but this does not seem to work for me.

Is there any other work arounds?
 
Hi Troy,

Thank you for posting in MSDN managed newsgroup!

Based on my experience, if there is no any client codes intervening in the BeforeClose event, the true value of Cancel will stop the closing of Excel in
released version.

I'd suggest you can check whether some client codes control the closing procedure which disables the Cancel. Furthermore, you will need to install
the released version of Visual Studio Tools for Office System 2003. The beta version may contain some bugs which cause this issue.

Please feel free to let me know if you have any further questions.

Does this answer your question? Thank you for using Microsoft NewsGroup!

Wei-Dong Xu
Microsoft Product Support Services
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi Troy,
I am using .NET Tools for Office with Excel 2003 Beta.

There is a 'Cancel' flag in the BeforeClose event and if
it is assigned the value of 'True' it is supposed to stop
Excel for closing, but this does not seem to work for me.

Is there any other work arounds?

This was a known issue in the betas of VSTO, but has been fixed (I
believe) in the release version.

Regards

Stephen Bullen
Microsoft MVP - Excel
www.BMSLtd.co.uk
 
Hi Onedaywhen,
I tested this on VSTO 2003 and conclude it has not been fixed.

I just downloaded the released version from MSDN and installed it. I
used the following code to test it:

Private Sub ThisWorkbook_BeforeClose(ByRef Cancel As Boolean) _
Handles ThisWorkbook.BeforeClose

MsgBox(ThisWorkbook.Name)
Cancel = (UCase(ThisWorkbook.Name) = "BOOK1.XLS")
End Sub

I found that when I saved the workbook as book1.xls and tried to close
it, it didn't close. When I saved it as book2.xls and tried to close
it, it closed fine. So I conclude that the Cancel property is working
fine in the released code.

Regards

Stephen Bullen
Microsoft MVP - Excel
www.BMSLtd.co.uk
 
Stepen,
I agree your results.

I was using C# when I tested this last week so I did a re-test using:

protected void ThisWorkbook_BeforeClose(ref bool Cancel)
{
if (ThisWorkbook.Name=="Book1.xls")
Cancel = true;
}

I don't know what went wrong last week but today I got the same
results as you. I too now conclude that the Cancel property is working
fine in the released code.

Apologies for any confusion caused.

--
 
Hi,

Thank you for replying!

You are all welcome!

Thank you once more for using Microsoft NewsGroup!

Wei-Dong Xu
Microsoft Product Support Services
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top