Is there any possibility to create and open XLSX (not macro) file generated by EPPlus with forced show "Save as dialog" before closing Excel?
My scenario:
I create XLSX file with EPPlus and store it to temporary folder of my application. Then I immediately call this file to run (Excel will open and my file is loaded). Without any changes I close Excel - and in this moment I want to force dialog "Save as" to save this file into other directory (not my temporary). Can you force display this dialog by any property of file (or other way)?
Solved for XLSM:
If someone of you need show this "Save as" dialog for Excel macro file (XLSM) using EPPlus, this is the way:
OfficeOpenXml.ExcelPackage Package;
Package.Workbook.CreateVBAProject();
OfficeOpenXml.VBA.ExcelVBAModule excelVbaModule =
Package.Workbook.VbaProject.Modules.AddModule("Module1");
StringBuilder mac = new StringBuilder();
mac.AppendLine("Sub Auto_Close()");
mac.AppendLine("Application.Dialogs(xlDialogSaveAs).Show");
mac.AppendLine("End Sub" );
excelVbaModule.Code = mac.ToString();
Package.Save()
Can you help me with not macro file? (But maybe it is not possible)
Thanks.
What I did based on your responses?
I try using SaveAs
(instead of the original .Save()
) from EPPlus:
System.IO.FileInfo fileInfo = new System.IO.FileInfo(targetTemporaryFile);
if (fileInfo.Exists) { fileInfo.Delete(); }
Package.SaveAs(fileInfo);
But no dialog was displayed.