Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / December 2004

Tip: Looking for answers? Try searching our database.

Cannot set Cancel param in Excel BeforeSave

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
richard - 22 Dec 2004 14:51 GMT
According to the article
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odc_vsto2003_ta
/html/VSTOFAQ.asp

it is a known problem that certain events cannot be cancelled programatically
when using the Excel PIA.
Does anyone know if this is going to be fixed? Does anyone know a smart
workaround (hack) that can be used in C# to set the Cancel param?

Any ideas gratefully received.
richard - 22 Dec 2004 17:45 GMT
Okay, I've managed to hack a "solution".
I went down the route of referencing the Save & Save As CommandBarButtons
and then assigning my own handler to their Click events. This worked because
the CancelDefault ref param *does* work. However, this does not address the
Ctrl-S keyboard shortcut. Application.OnKey could have worked had the
function I wanted to use been addressable in the COM Add-In I'm using. It
wasn't, as it was in a satellite assembly that is started dynamically. Yes, I
guess I could have re-jigged my abstract class to allow this assembly to
register its interest with the parent COM Add-In, but that seemed too much
re-engineering to get round a feature that MS are hopefully addressing ;-)
So, my terribly elegant solution is to leave the wiring exactly as it was
where I register a handler with the Workbook's BeforeSave event. I have left
my alternate Save methods there, and continue to set the (non-functioning)
Cancel ref parameter to true. My magic line of code to get rid of the pesky
dialog is... wait for it...

_myWorkbook.Application.SendKeys("{ESC}", true);

I may have to monitor whether setting the wait arg to true rather than false
gets me into trouble.

Here's hoping someone finds this of use :-)

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.