2

I open an excel document from web url with the code:

<a href="ms-excel:ofe|u|https://www.example.com/test.xlsx">Open with excel</a>

An empty excel book is opened successfully. According to scenario for my excel vsto project, the document has to be saved in our cloud instead of user's pc. Therefore, I repurposed the excel's save events, created a method called CustomSave and wrote my upload code inside there.

My ribbon and c# code can be seen below :

MainRibbon.xml

 <commands>
    <command idMso="ThemeSaveCurrent" onAction="CustomSave"/>
    <command idMso="FileSaveAsExcelXlsb" onAction="CustomSave"/>
    <command idMso="ChartSaveTemplates" onAction="CustomSave"/>
    <command idMso="WindowSaveWorkspace" onAction="CustomSave"/>
    <command idMso="FileSaveACopy" onAction="CustomSave"/>
    <command idMso="FileSave" onAction="CustomSave" />
    <command idMso="FileSaveAs" onAction="CustomSave" />
    <command idMso="FileSaveAsMenu" onAction="CustomSave" />
    <command idMso="FileSaveAsExcelXlsx" onAction="CustomSave" />
    <command idMso="FileSaveAsExcelXlsb" onAction="CustomSave"  />
    <command idMso="FileSaveAsExcel97_2003" onAction="CustomSave" />
    <command idMso="FileSaveAsOtherFormats" onAction="CustomSave"/>
  </commands>

MainRibbon.cs

public void CustomSave(IRibbonControl control, bool cancelDefault)
{              
    MyUploadMethod(); //Method which uploads current document to the cloud.
    cancelDefault = false;
}

I also added WorkbookBeforeSave method :

ThisAddIn.cs

private void WorkbookBeforeSave(Excel.Workbook workbook, bool SaveAsUI,ref bool Cancel)
{
    Cancel = true;
    SaveAsUI = false;
    MyUploadMethod(); //Method which uploads current document to the cloud.

}

private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
    this.Application.WorkbookBeforeSave += WorkbookBeforeSave;

}

Although my CustomSave method intercepts all save events in the excel as expected, when I press ctrl+s from keyborad it does not go inside the CustomSave method or WorkbookBeforeSave method. When I click ctrl+s keys, I get a warning below :

Click for image

I did the same thing for word and power point without a problem but could not do it for excel. By the way when I open the document from web, document status becomes always read only and it's status doesn't change unless I save it locally. I can not upload the document directly to the cloud without saving it locally. But I don't want to save the document to the local pc. I would be glad if you have any suggestion for my problem.

Thorux
  • 197
  • 1
  • 1
  • 11

0 Answers0