This project has moved. For the latest updates, please go here.

Does ClosedXML/Open XML SDK work with xlsm files?

Jan 19, 2012 at 6:49 AM

This is probably a stupid question but I'm new to Office XML.  I need to use VBA in my Excel solution.  Will ClosedXML work ok with xlsm files?  I would expect so but until just now I didn't even realize xlsx files weren't "macro enabled"!

Coordinator
Jan 19, 2012 at 1:53 PM

It can open/save files with macros but it cannot add new VBA code. Just create an xlsm file with the macros and use it as a template.

Jan 20, 2012 at 5:17 AM

Do you know if I do need to add or change VBA code if I could just use Open XML to do that after (or even before) processing my xlsm file with ClosedXML?

 

Coordinator
Jan 21, 2012 at 11:01 PM

ClosedXML opens/saves valid Open XML files so you can modify the files before and/or after using this library.

Developer
Mar 5, 2014 at 3:29 PM
I need to create new XLSM file and modify existing file. I don't need to add new VBA code.

I've used the sample code and the resulting file is actually an XLSX file.

I've opened an issue:
https://closedxml.codeplex.com/workitem/9245

Is there anything I am doing wrong?
var workbook = new XLWorkbook();
var worksheet = workbook.Worksheets.Add("Sample Sheet");
worksheet.Cell("A1").Value = "Hello World!";
workbook.SaveAs("HelloWorld.xlsm");
Developer
Mar 6, 2014 at 1:24 PM
I've added a patch that enables creating and modifying XLSM files:
https://closedxml.codeplex.com/workitem/9245

Hope it helps