0
votes

How do I disable Excel save button or override it's default functionality? I have a VSTO Excel project, and there is no need to save the Excel Workbook itself because we are using our own ways to save the document data using WCF. It even creates problems for us when user doesn't have writting rights: then he gets a "save as" dialog which still does nothing because I cancel the save event using following code:

void ThisWorkbook_BeforeSave(bool SaveAsUI, ref bool Cancel)
    {
        Cancel = true;
    }

I can also cancel the "do you want to save" prompt using:

 void ThisWorkbook_BeforeClose(ref bool Cancel)
    {
        this.Saved = true;
    }

But if the file is read-only and I click the Save button, then I get a "this file is read-only" message. I don't want to get it.

2

2 Answers

2
votes

If you are using Office 2010 or 2007 you could load a Ribbon that disables the built in commands save and save-as.

The most comprehensive documentation I know for the Ribbon markup is here:

MSDN Customise the Office Fluent Ribbon Interface - 1

MSDN Customise the Office Fluent Ribbon Interface - 2

MSDN Customise the Office Fluent Ribbon Interface - 3

0
votes

I figured out that if you create a Template project instead of a Workbook project, then nothing happens when you click Save if my code from the question is applied.