How to open an Excel 2013 Macro Enabled Template?
8 Dec 20232 minutes to read
You can open and save an Excel 2013 Macro Enabled Template to XLSM (Excel 2013 Macro Enabled Document) format. The following code snippet illustrates this.
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
//Open an existing XLTM file
FileStream inputStream = new FileStream("Sample.xltm", FileMode.Open, FileAccess.Read);
IWorkbook workbook = application.Workbooks.Open(inputStream, ExcelOpenType.Automatic);
//Save the file as XLSM
FileStream outputStream = new FileStream("Output.xlsm", FileMode.OpenOrCreate, FileAccess.ReadWrite);
workbook.SaveAs(outputStream);
workbook.Close();
excelEngine.Dispose();
}
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
//Open an existing XLTM file
IWorkbook workbook = application.Workbooks.Open("Sample.xltm", ExcelOpenType.Automatic);
//Save the file as XLSM
workbook.SaveAs("Output.xlsm");
}
Using excelEngine As ExcelEngine = New ExcelEngine()
Dim application As IApplication = excelEngine.Excel
application.DefaultVersion = ExcelVersion.Excel2013
'Open an existing XLTM file
Dim workbook As IWorkbook = application.Workbooks.Open("Sample.xltm", ExcelOpenType.Automatic)
'Save the file as XLSM
workbook.SaveAs("Output.xlsm")
End Using