Home » SQL Server

WorkbookBeforeSave event SaveAsUI always true

I have a VSTO excel addin developed in .net 3.5 and recently ported to target .net 4

I have wired up the Application.WorkbookBeforeSave event during addin startup.

What I am now seeing is that the SaveAsUI parameter is always true whenever this event fires. Previously, in 3.5 it would be true only when you'd expect, based on whether the "save as" dialog was to be shown.

Anyone seen anything like this?



8 Answers Found


Answer 1

Hello Roger,

Thanks for posting. I read your post carefully. To get a better understanding on this issue, would you mind clarifying some points for us?

Which version of Office and Visual Studio you are involved in? You are working with an document-level project or an application  one? Which button you pressed to trigger WorkbookBeforeSave event?

Based on my observation, if we click SaveAs button to save  as this workbook, it also will trigger this event, and the SaveAsUI will be always true. If we click Save button, SaveAsUI might be true  the first time. For this point, if you have any concern for this, please feel free to follow up.

We are looking forward to you reply. Have a nice day!

Best regards,
Bessie Zhao - MSFT
MSDN Subscriber Support in Forum
If you have any feedback of our support, please contact msdnmg@microsoft.com.

Please remember to mark the replies as answers if they help and unmark them if they provide no help.

Answer 2

Thanks for your response.  In answer to your questions...

This is office 2007 on a variety of OS's using VS2010 to build an application  level addin.

To reproduce, create a new project in vs2010 using the template: Office / 2007 / Excel 2007 Add-in

Use the default target  Framework of .net 4 or the .net 4 client profile.

Replace the contents of ThisAddin.cs with the code at the end of this post.

Run the addin  by pressing F5 or however you like to do it.

You have a blank workbook. 

Press ctrl-s to save  it.   The save as dialog  appears, and you see that the diagnostic message indicates that the saveAs parameter  is True, which is what you would expect  it to be.   Save the file someplace.

Modify a cell in the workbook.  Then press ctrl-s again.  Now, the document is saved with no save as dialog appearing, as you'd expect. However, note that the diagnostic message indicates that the saveAs parameter is True. We expect false in this case, since no saveAs dialog is shown.  

Repeat as often as you like, using Ctrl-S, the Save button in the QAT, and the Save button in the Application menu, always the same result - no dialog but diagnostic message say saveAs is True.

Now change the project to target .net 3.5 (don't forget to do build/clean first!) and repeat the steps above. Now, the behavior of the diagnostic message is as you would expect - true  the first time when the save as dialog is shown, false thereafter (unless of course you actually do a save as to a new file)

Not shown, but also true, is the behavior when the save operation is initiated from code, using the Workbook.Save method. The parameter is always True, even when saving with no saveAs UI showing.


Hope that clarifies. Sample addin code follows...


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Excel = Microsoft.Office.Interop.Excel;
using Office = Microsoft.Office.Core;
using Microsoft.Office.Tools.Excel;
using System.Diagnostics;

namespace BeforeSaveEvent
    public partial class ThisAddIn
        private void ThisAddIn_Startup(object sender, System.EventArgs e)
            Application.WorkbookBeforeSave += Application_WorkbookBeforeSave;

        private void ThisAddIn_Shutdown(object sender, System.EventArgs e)

        private void Application_WorkbookBeforeSave(Excel.Workbook workbook, bool saveAs, ref bool cancel)
            Trace.WriteLine("Application_WorkbookBeforeSave saveAs = " + saveAs);

        #region VSTO generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InternalStartup()
            this.Startup += new System.EventHandler(ThisAddIn_Startup);
            this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);


Answer 3

Hello again Roger,

Thanks for the further information. By following the steps, I was able to reproduce the issue you are seeing. I also have created an Excel Add-in under Office 2010 and Visual Studio 2010. By change the version of .NET Framework, the scenario also happens. So I think this issue is probably related to be .NET Framework 4.0.

I have reported a feedback through Visual Studio & .NET Connect site:
http://connect.microsoft.com/VisualStudio/feedback/details/573270/saveasui-in-workbookbeforesave-event-hander-is-always-true. This issue will be routed to the product unit who works on this specific feature area for triage and resolution. I’ll paste all responses from the product unit in this thread. And you also can click the link and add the feedback to your watch list (you need to log in using your account) so that you can get informed as soon as product units respond. It may be some time before we get response from product unit. Please be patient.

Best regards,
Bessie Zhao - MSFT
MSDN Subscriber Support in Forum
If you have any feedback of our support, please contact msdnmg@microsoft.com.


Answer 4

Hello again Roger,

I am writing to check the status of the issue on your side. If you have any questions or concerns, please feel free to let me know. I will be more than happy to be of assistance.

Best regards,
Bessie Zhao - MSFT
MSDN Subscriber Support in Forum
If you have any feedback of our support, please contact msdnmg@microsoft.com.


Answer 5

I see that you submitted this as a bug to the connect site, so I guess I'm waiting to see how that goes.  The problem puts us in a bit of a hard place - we can kind of work around it but not totally.  If there's anything you can do to expedite it with the product group, that would be the most valuable thing.

Thanks again



Answer 6

Hi Roger,

We have found this issue to be a bug in .Net Framework.

There are some workarounds you can try:

1. Disable Embedding the Microsoft.Office.Interop.Excel.dll in the vsto  customization by Setting the EmbedInteropType property to false for Microsoft.Office.Interop.Excel.dll under References in Solution Explorer.
2. Or use the VBAInterop feature of VSTO to handle the event  in VBA and then call a function in VSTO customization with the parameters passed to the VBA event. For more information about VBA Interop in VSTO customization please have a look at http://blogs.msdn.com/b/bethmassi/archive/2009/11/05/interop-between-vba-and-visual-studio-office-solutions-vsto.aspx



Answer 7

Well, the typelib embedding feature is the reason we moved to .net 4 in the first place, so we won't be disabling it.

The VBAInterop approach sounds like it might be workable for us, so I'm going to try and pursue that.

Question though - should there be some updates about this attached to that connect site?

Thanks for your help here


Answer 8

It looks like hooking up a VBA event  handler for Application.BeforeWorkbookSave and then having that forward the call into our VSTO addin  does the trick as a workaround until the issue can be properly fixed in the framework.

Thank you very much for following this through and guiding it through the connect site and process.






I need to determine when a user cancels a print job so I've set up the following code

printDoc.EndPrint += new PrintEventHandler(OnPrintEnded);

The function OnPrintEnded is as follows:

void OnPrintEnded(object sender, System.Drawing.Printing.PrintEventArgs e)

      if (e.Cancel == true)
        //tell the user it was cancelled

the problem is e.Cancel never gets set to true even when the user cancels the print by pressing the cancel button and the print job gets cancelled from the printer.

Does anyone know why?




I wonder why that is? I have this code in my HTML page:

<button onclick="document.location.reload(true)">reload</button>

and when clicking this button the page refreshes, but my sinked events are not invoked. Why?

I have code running in the Datatable.ColumnChanging event in my dataset. This dataset underlies a form and conventional drag/drop controls are in place for data entry.

when the event triggers and runs, I am running code in the form that checks the dataset.HasChanges property. It is showing False. But this is immediately after the ColumnChanging event has been triggered.

Okay, I see by others posts and MSDN that .HasChanges will only be true after moving off the row with the changed column. I have also noted lots of discussion about the advanced binding property of DataSourceUpdateMode, but that does not address this issue.

I guess I can do this by checking the state of the row for the binding source. Just seems odd that the event behind the dataset can be triggered and that does not change the dataset.HasChanges property.

I have a parameter test that takes a boolean value, sets it to a property, and then reads it back to see if I got the correct value.  At the end of the parameter test, I have an assert to check the equality.  The code looks like this:



publicvoid PropertyGetSet(MyObject target, bool value)
   target.MyProperty = value;
   bool result = target.MyProperty;

   PexAssert.AreEqual<bool>(value, result)


I had Pex generate values for me, and the tests passed for normal boolean values, but Pex generated a test case that called my parameter test like this:


this.PropertyGetSet(target, PexSafeHelpers.ByteToBoolean((byte)128));


And the test fails on the PexAssert.  The exception message is:

Microsoft.Pex.Framework.Exceptions.PexAssertFailedException: Expected 'True', got 'True'

What's going on?  Shouldn't the test pass?



imagine you have a ComboBox with the following entries in the DropDown list:
1, 5, 10, 15

Now follow up this scenario:
- open DropDown list
- type 13 in the edit field -> 10 is selected in DropDown list
- press "Enter"

As result DropDown list is closed and 10 is placed in the edit field.
How to override this behaviour so that 13 would be not overwritten after pressing "Enter"?




I am checking my codes using Event Flow DeBugger. I am finding duplicated events One original and one retract event. Can any one help me why is retract event being genrated. And if this event is resulting in Error or Duplicate Events.

Specially i would like to understand the logic of retract event in cep.



I'm having trouble getting a list of today's events from a default calendar.

I've tried the following two CAML queries:

 <FieldRef Name=\"EventDate\" />
 <FieldRef Name=\"EndDate\" />
 <FieldRef Name=\"RecurrenceID\" />
 <Value Type=\"DateTime\"><Month/></Value></DateRangesOverlap></Where>

Which resulted in the following Exception:

One or more field types are not installed properly. Go to the list settings page to delete these fields.0x81020014

The calendar list is a default calendar list ie. no additional fields and no changes to the Event content type.

The second CAML query I tried was:


Which worked however it did not include multi-day events that started before today or any recurring events.

Any help would be greatly appreciated!



Hi all...

i am using VS 2008 and just started to work with XAML and WPF. while opening in page(.xaml) in design mode i'm getting the error like this ...

"Only TrueType fonts are supported and this is not a TrueType font".

how to solve this problem .please any one can help me.

thank you


HOWTO Capture an event for a button when its "disabled" is set true.

Please help. When a HTML button has its "diabled" set true, no onpropertychange event is fired in IE8. Is there anyway to fix this?





I want to change the TextBox border color if certain event is true.


For example, in a GroupBox, there is a TextBox and a Button.

If the TextBox is empty, and I click the button, I want the TextBox border color to change to red.

If the TextBox is not empty, I want The border color to remain unchanged.


How do I change the TextBox border color on a certain event?


When we call an Oracle procedure using BizTalk Adapter Pack v2, it fails because not all the elements in the XML document are present. According to the documentation we must add all missing elements with the attribute xsi:nil="true". This is a very fundamental change compared to version v1.

Typically there are 50 parameters in a call and some 10 or so might be missing. Potentially 48 could be missing. What is the easiest way to ensure that all the elements are present in the XML. Map (what functoid to use?), custom xslt, some sort of change in the generated schemas?

Thanks in advance.

BTW, This is from the documentation

Outbound operations: In the previous version of the Oracle Database adapter, if you executed stored procedures in which some parameters are not specified in the input XML file, a NULL value was sent for those parameters. Even if default values were specified for these parameters in the stored procedure, still a NULL value was sent for those parameters. In the current version of the adapter, no value is sent for the parameters that do not have a value specified in the input XML file. If a default value is specified in the stored procedure, the Oracle database uses that value because no value was sent by the adapter. If a NULL value needs to be sent, the user needs to specify a NULL node in the input XML file by setting the value of “nil” attribute to “true.”


I'm getting this error message with some code which si heavily using template programming.

The compiler does not even come close to allocatate any of the available RAM (8GB).

I'm running the 64bit compiler of visual C++ 2010.

Anybody interested in the source code?

The same code compiles with G++ 4.3.4


I am using MS Visual Studio 2205 Version 8.0.50727.42 and MS.Net Framework Version 2.0.50727 SP2

I created a form that requires the user to enter a date into the textbox.

I then use the IsDate function to check if the entry is a valid date.  IF Not IsDate(fieldname) then send message back to user on form, otherwise continue.

If something like this is enterred - 06/090/10 - It passes the IsDate question and of course fails at the database level when inserting to a datetime field.  Although there is a three character day, it still passes.

Any thoughts? 


From my BuildLog.txt I see the Get task being executed as:


Target "CoreGet" in file "C:\Program Files\MSBuild\Microsoft\VisualStudio\TeamBuild\Microsoft.TeamFoundation.Build.targets" from project "E:\TFSBuild\ELABTFSBuildFolder\AEDCSE\SP_Web_Main_Nightly\BuildType\TFSBuild.proj":
Using "Get" task from assembly "C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\PrivateAssemblies\Microsoft.TeamFoundation.Build.Tasks.VersionControl.dll".
Task "Get"
  Get TeamFoundationServerUrl="http://dlev220:8080/" BuildUri="vstfs:///Build/Build/1537" Force=False Overwrite=False PopulateOutput=False Preview=False Recursive=True Version="C13230" Workspace="DLEV219_4"
Done executing task "Get".
Task "SetBuildProperties" skipped, due to false condition; ( '$(GetVersion)' != '$(SourceGetVersion)' ) was evaluated as ( 'C13230' != 'C13230' ).
Done building target "CoreGet" in project "TFSBuild.proj".


I want a completely clean, full download and build, so I added to the bottom of my TFSBuild.proj file:




But the "Get" task above still has Force=false. Why isn't TFS setting Force=true?




I'm learning from the great  article http://msdn.microsoft.com/en-us/magazine/ee336128.aspx with VS 2010, but, on time to compile,  i have a error in BlogManager project  with the next message: '''UseDataServiceCollection' parameter cannot be set to 'true' since the parameter is not support for 'UseDataServiceCollection' framework version.''. According with the article, to enable Data binding,   I add to Reference.datasvcmap file the next xml elements: 

    <Parameter Name="UseDataServiceCollection" Value="true" />
    <Parameter Name="Version" Value="2.0" />

but, after refresh the reference service,  the reference.cs file  for this reference service  is in blank, no code was generated.

Initial idea: Silverlight 3.0 System.Data.Services.Client does not implement EntitySetAttribute in System.Data.Services.Common.

Question:Is necesary change the reference?

Any idea about how to resolve this issue?


Thanks for your help


I am trying to lazy-load satellite XAP files on-demand using MEF but am experiencing a problem using the ImportMany attribute with AllowRecomposition set to true.  I have wired-up the CollectedChanged attribute on my collection object and see that each time a change is made, new instances of the previous imports are created and added to the collection instead of just adding the new ones.  Here a bit of my code:

[ImportMany(AllowRecomposition = true)]
public ObservableCollection<IPlugin> Plugins

To add a new XAP file, I use the following code:

catalog = new DeploymentCatalog(uri);

So, what am I missing or doing wrong?  I would expect that a new item (or items) would be added to my collection when a new XAP file is added to the catalog.  I need to retain the original object when a second is added.



I gotta CalenderControl TextBox "txtDate" in a content page, when I set its property as READ ONLY , then im unable to access it in my page.

However when i remove it , I can get the values thru "txtDate.Text".But I need to set its property as READONLY..

Any suggestions??? Any help appreciable...

Cheers :-)




We have datagrid, each row contains a rowheader and 2 cells of list box. We enabled

But CodedUITest builder can see the list box(cells) of rows 1-~10 after i scroll down to like 14th row, it doesn't see any listbox(cells) of rows. Can anybody help me with this issue. We can't disable virtualization just for this automation, because it affects speed of the application!




I have successfully created a Silverlight 4 business application that uses SQL Azure ASP.NET membership and that deploys and works in the development fabric and on the cloud. I am able to register new users and log in.

I believe I then successfully added my HTTPS endpoint correctly but when I edit AuthenticationService.cs to require a secure endpoint:

 [EnableClientAccess(RequiresSecureEndpoint = true)]   
 public class AuthenticationService : AuthenticationBase<User> { }

I get this error when I browse to my development fabric on

"Load operation failed for query 'GetUser'. An error occurred while trying to make a request to URI ' '. This could be due to attempting to access a service in a cross-domain way without a proper cross-domain policy in place, or a policy that is unsuitable for SOAP services. You may need to contact the owner...'

I then added a crossdomain.xml and clientaccesspolicy.xml to the root of my web application and also in ClientBin to no help.

When I then ran HTTPS on my development fabric using I do not see this error. This made me realize that the GetUser operation is not using the correct HTTPS port of 444 . Why is it trying the HTTP port of 81?

The same situation occurs for me when deployed on the cloud.

I'd appreciate any help on this...


For more details here are the steps I basically followed...

1. Create the Silverlight 4 Business App for the Cloud, but skip the table storage bit



2. Create a asp.net membership database on SQL Azure and wire app created in step 1 for it



3. Test and check that it works

You should be able to deploy this app, register users and login using HTTP.


4.Add an https endpoint to an azure cloud service



5. Modify AuthenticationService.cs to require a secure endpoint

[EnableClientAccess(RequiresSecureEndpoint = true)]   
public class AuthenticationService : AuthenticationBase<User> { }


Step 5 is where things fail using HTTP but works from HTTPS.



















Please help. I get this error when i try to run a function that uses SyncFusion DocIO control on azure. It runs fine on local machine. I set 'Copy Local' of the reference to true.


I tried publishing it 5-6 times. Still no luck

Server Error in '/' Application.
Could not load file or assembly 'Syncfusion.Core, Version=, Culture=neutral, PublicKeyToken=632609b4d040f6b4' or one of its dependencies. The system cannot find the file specified. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.IO.FileNotFoundException: Could not load file or assembly 'Syncfusion.Core, Version=, Culture=neutral, PublicKeyToken=632609b4d040f6b4' or one of its dependencies. The system cannot find the file specified.


Code is


        Dim dataPath As String = path
        ' Creating a new document.
        Dim document As DLS.WordDocument = New DLS.WordDocument()
        ' Load template
        document.Open(dataPath, FormatType.Doc)
        ' Merge Template fields with user entered data.
        document.MailMerge.RemoveEmptyParagraphs = True
        'To clear the fields with empty value
        document.MailMerge.ClearFields = True
        'Clear the map fields
        document.Save("out.doc", FormatType.Doc, Response, HttpContentDisposition.InBrowser)


<< Previous      Next >>

Microsoft   |   Windows   |   Visual Studio   |   Sharepoint   |   Azure