This project has moved and is read-only. For the latest updates, please go here.

Does ClosedXML/Open XML SDK work with xlsm files?

Jan 19, 2012 at 7: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"!

Jan 19, 2012 at 2: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 6: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?


Jan 22, 2012 at 12:01 AM

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

Mar 5, 2014 at 4: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:

Is there anything I am doing wrong?
var workbook = new XLWorkbook();
var worksheet = workbook.Worksheets.Add("Sample Sheet");
worksheet.Cell("A1").Value = "Hello World!";
Mar 6, 2014 at 2:24 PM
I've added a patch that enables creating and modifying XLSM files:

Hope it helps