DEV Community

IronSoftware
IronSoftware

Posted on • Originally published at ironsoftware.com

1 1

Preserve Excel Macros in XLSM (Code Example)

IronXL supports macros in Excel. Simply load, edit and save an XSLM document - and macros will not be edited or disabled.

XLSX files may be saved as XLSM file extension to enable macros.

To disable macros, simply save an XSLM with the XLSX file extension.

C#:

using IronXL;

WorkBook workbook = WorkBook.Load("test.xlsm");
//You can load xlsm file and work with it as you wish.
var sheet = workbook.CreateWorkSheet("one more sheet");
sheet["A1:B2"].Value = "Hi";
//Then you can save it with xlsm extension and all macros will be preserved.
workbook.SaveAs("test.edit.xlsm");
Enter fullscreen mode Exit fullscreen mode

VB:

Imports IronXL

Private workbook As WorkBook = WorkBook.Load("test.xlsm")
'You can load xlsm file and work with it as you wish.
Private sheet = workbook.CreateWorkSheet("one more sheet")
Private sheet("A1:B2").Value = "Hi"
'Then you can save it with xlsm extension and all macros will be preserved.
workbook.SaveAs("test.edit.xlsm")
Enter fullscreen mode Exit fullscreen mode

Speedy emails, satisfied customers

Postmark Image

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay