We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Extract VBA Code or macros from Excel files in .NET


Please, can you tell me is it possible to extract VBA code from Excel files with Aspose.Cells .NET?

Thank you,

Hi Alen,

Thanks for choosing Aspose as your File Format Expert.
I am afraid, currently we do not support the functionality to Extract VBA code from Excel Files. We have logged a ā€œNew Featureā€ request in our Tracking System under Ticket ID CELLSNET-26967. We will update you here, when this functionality is available in Aspose.Cells for .NET.
Right now, we can Preserve Macros if the Excel file accessed through Aspose.Cells have Macros in it. Also, we can Remove Macros code, using Workbook.RemoveMacro method.


Thanks for using Aspose.Cells.

We only plan to create,
manipulate or embed VBA codes/ macros later. We however cannot support
to run or execute macros. Does it fit your needs?


We are pleased to inform you that the library (Aspose.Cells for .NET) now supports to create, manipulate or remove vba codes/macros feature(s) with lots of enhancements. Now you have number of ways to do the task for your requirements:
Option 1:
Call Workbook.RemoveMacro() method to remove the macros and vba codes in the Excel file.

Option 2:
Remove VBA modules in the spreadsheet, please use the following sample code:

for (int i = vbaModuleCollection.getCount() - 1; i >= 0; i--) {
System.out.println("Removed " + i+1);

Option 3:
Exclude VBA codes/macros while loading the file into Aspose.Cells object model, see the sample code segment for your reference:
Sample code:

//Import everything except VBA codes/macros.
var loadFilter = new LoadFilter(LoadDataFilterOptions.All & ~LoadDataFilterOptions.VBA);
            var asposeOptions = new Aspose.Cells.LoadOptions { LoadFilter = loadFilter };
            var wb = new Workbook("e:\\test2\\Book1.xlsx", asposeOptions);

We recommend you see the documents in the section on how to manage/manipulate VBA code and macros via Aspose.Cells APIs:
Manipulate Macros or VBA Codes

You can download the latest demos here.