Create manipulate and remove vba codes or macros from Excel file in .NET

Hello,

Could you please throw light on your plans about macro management for Excel, precisely I wonder about macro inserting. The current version allows to remove macro only.

We send generated file (XLSM, Office 2010) to user1, he works with the file and sends it back to us (using macro or online web form). Then we make some processing and send the file to user2. Our file contains the special macros for checking user input and sending the file to us right from the excel. The problem is we can’t be sure that the file received from user1 contains macros (we have such experience when user sends the file without macros - which were deleted due to user’s security settings). Anyway we have to provide user2 with the correct file which contains all the macros. This is why we need macro inserting.

Now we act the next way:
We have a template for the file which already has the macros we need. We copy content of the received (from user1) file to the template sheet by sheet. Thus we secure ourselves against sending the file with bad macros to user2. But we are faced with a huge number of issues during data copy to the template from the received file. It is very hard, we are fighting with them over the last 6 months. We have really big project and each update of Aspose lib kicks on something and we have to fix over and over. It becomes a headache to do this.

Just imagine how it would be easy to insert the macros if they were deleted. Could you please review the ability to implement such feature in Aspose.Cells lib, we are really interested in it.

Many thanks,
Andrey

Hi,

Aspose.Cells for .NET cannot add new macros or modify the existing ones. However, it preserves the existing ones.

If your source file has some macros then it will not delete them and preserve in the output file as it is.

Its difficult feature to develop the ability to add/modify macros and we have no plans of it to implement in near future.

Please download and try the latest version:
Aspose.Cells
for .NET v7.0.4.6

, it should preserve your macros.

If it does not preserve, then please provide us your sample code and source files to replicate the problem, we will fix it asap.

@iLevel,

Using latest versions of Aspose.Cells, you can create, manipulate or remove vba codes/macros. We have improved the features recently. You can also assign macros to controls. For example, there are number of ways to remove vba codes or macros:

  1. If you do not want to export VBA project/macros in the output file, please call Workbook.RemoveMacro() method.
  2. If you want to remove VBA modes, please use the following code:
for (int i = vbaModuleCollection.getCount() - 1; i >= 0; i--) {
vbaModuleCollection.removeAt(i);
System.out.println("Removed " + i+1);
}

Another sophisticated way can be you may exclude VBA codes/macros while loading the file into Aspose.Cells object model, see the sample code segment for your reference:
e.g
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);
.........

For more information on how to manage/manipulate VBA code and macros via Aspose.Cells APIs, please follow the links in the section for Aspose.Cells Documenation:
Docs

Download the latest version of Aspose.Cells for .NET from the following link:
Aspose.Cells for .NET (Latest Version)

You can download the latest demos here.