Combining Two Work books And retaining the macro

Hi,

In our project we are using aspose 5.1.3.

Following are the scenario and we are trying to retain the VBA macro in resultant workbook.

1. we try to combine (aspose workbbok.combine method) one workbook which is of type .xlsx with the workbook which is of type .Xlsm and when we save it, we save it as .Xlsm.but we could not retain the macro.is their any way that we can retain the macro.

2. we try to combine two workbooks of type .xlsm and each one having a macro now combine workbook should have two macro. Is it possible to retain both the macro in resulatant workbook.

Thanks

Gyan

Hi,

Thanks for your question and using Aspose.Cells for .NET.

Well, that’s not possible, because Aspose.Cells does not understand macros containers, it can preserve the macros within workbook but when you copy one wordbook into another workbook, macros are not copied.

We will look into this issue and see if such issue can be refrained in future while combining the workbooks.

This issue has been logged as CELLSNET-40861.

Below is my test code, I have attached two xlsm files, when they are combined, macro of one workbook is lost.

C#


string filePath1 = @“F:\Shak-Data-RW\Downloads\source.xlsm”;

string filePath2 = @“F:\Shak-Data-RW\Downloads\source2.xlsm”;


Workbook workbook1 = new Workbook(filePath1);

Workbook workbook2 = new Workbook(filePath2);


workbook1.Combine(workbook2);

workbook1.Save(filePath1 + “.out.xlsm”);

@gyan

Thanks for using Aspose APIs.

We are afraid, we are unable to fix your issue logged as CELLSNET-40861 because of its complexity. We cannot parse the code in VBA project, so we cannot merge two VBA projects.