none
c# programming language using excel 2013 save as RRS feed

All replies

  • Hello,

    You need to specify the file format (the second argument) to the SaveAs method. 

    For example, in Excel 2007-2016, this will fail if the ActiveWorkbook is not an xlsm file

    ActiveWorkbook.SaveAs "D:\test.xlsm"

    This code will always work


    ActiveWorkbook.SaveAs "D:\test.xlsm", fileformat:=52 

    ' 52 = xlOpenXMLWorkbookMacroEnabled = xlsm (with macro's in 2007-2016)

    As for C#, the following code works like a charm on my machine with Excel 2013 installed:

    Application.ActiveWorkbook.SaveAs(@"H:\wb.xslm", Excel.XlFileFormat.xlOpenXMLWorkbookMacroEnabled,
                    Type.Missing, Type.Missing, Type.Missing, Type.Missing, Excel.XlSaveAsAccessMode.xlNoChange, Type.Missing,
                    Type.Missing, Type.Missing, Type.Missing, Type.Missing
                    );


    profile for Eugene Astafiev at Stack Overflow, Q&A for professional and enthusiast programmers


    Monday, November 28, 2016 8:32 PM