View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
onedaywhen onedaywhen is offline
external usenet poster
 
Posts: 459
Default Cancelling the BeforeClose Event

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.

--

Stephen Bullen wrote in message ...
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