Workbook.copy not preserving vba in version 7.7.0.0

Hi


I was using 7.3.1.0 of Aspose.Cells .net and here I could do following:

Workbook1 (xlsm): contains vba code/macros
Workbook2(xlsx): contains sheets.

Workbook1.copy(workbook2) and this resulted in that all sheets from workbook2 where copied to workbook1 and the vba/macro code where preserved in this xlsm file.

Unfortanitly this is not the case in version 7.7.0.0 of Apose.Cells .net.

Could you please help me with this asap.

Thanks,
Ali

Hi,


Please download and try our latest version/fix: Aspose.Cells for .NET v7.7.0.4

If you still find the issue, kindly provide your template Excel files here, we will check your issue soon.

Thank you.

Hi Amjad,


I cant give you our code but as I wrote this is what we do;

We have some vba code in a xlsm file (workbook1) and sheets in another file xlsx (workbook2).

When calling workbook1.copy(workbook2) the vba code is preserved after saving workbook1 to the disk in version 7.3.1.0 as xlsm file.

This is not the case in version 7.7.0.0.

And the version you attached 7.7.0.4 didnt fix the problem.

Hi again,

After trying several versions I found out that the Workbook.Copy works fine until version 7.4.1.

In version 7.4.2 its not working with preserving the vba code.

Hope this helps.

br,

Ali

Hi Ali,

Thanks for your posting and using Aspose.Cells.

In order to investigate this issue, please provide us sample files. You can create some workbooks manually with test macros for demonstration purpose. We will look into this issue and help you asap.

Hi Shakeel,


I have just send you an email (with your own mailing system).

Please let me know If you have not received it.

br,
Ali

Hi Ali,

Thanks for your email and using Aspose.Cells.

We were able to observe this issue. When the workbook is copied using v7.7.0.4, then macros are lost in the output xlsm file. However when the workbook is copied using v7.4.1.0, then macros are preserved in the output xlsm file.

I have attached all the needed files to replicate this issue with the following source code. We have logged this issue in our database for investigation. We will look into it and resolve this issue. Once, the issue is resolved or we have some other update for you, we will let you know asap.

This issue has been logged as CELLSNET-42293.

C#


string pathXlsx = @“F:\Shak-Data-RW\Downloads\test\AsposeTest\WebApplication1\WebApplication1\ExcelTemplates\Workbook2.xlsx”;

string pathXlsm = @“F:\Shak-Data-RW\Downloads\test\AsposeTest\WebApplication1\WebApplication1\ExcelTemplates\Workbook1.xlsm”;


Workbook xlsxFileWhereSheetShouldBeCopiedFrom = new Workbook(pathXlsx);


Workbook xlsmFileWhichContainsVBACodeWkb = new Workbook(pathXlsm);


xlsmFileWhichContainsVBACodeWkb.Copy(xlsxFileWhereSheetShouldBeCopiedFrom);


xlsmFileWhichContainsVBACodeWkb.Save(“copiedv7.7.0.4.xlsm”, SaveFormat.Xlsm);



Hi Ali,

Thanks for using Aspose.Cells.

If a workbook is copied, all old settings and data of the workbook should be
removed, so macros should be removed too.

It’s bug of older version 7.3.1.0
to preserve macros.

Hi Shakeel,

I am using this functionality in my application and the macro that is preserved isnt in the xlsx file which are copied, but in the xlsm file which the sheets are copied to.

And I see this as an functionality you have had in earlier version, which does not work now. See below link for an incident Amjad is talking about.

Here he says that Workbook.Copy should preserve vba code.

https://forum.aspose.com/t/99549

/Ali

Hi Ali,

Thanks for using Aspose.Cells.

We have logged your comment for consideration. We will look into it and see if this feature could be added again. Once, we will have some update or fix for you, we will let you know asap.

Hi Ali,

Thanks for using Aspose.Cells.

If you call destWorkbook.Copy(sourceWorkbook) method, the old macros of
destWorkbook will be removed and the macros of sourceWorkbook will be copied to
destWorkbook.

Hi,

I tried this, but the sheets from destWorkbook are also removed!!!

Did you try your suggestion with the code I send to u?

I tried it and here it does not preserve the sheets in the destWorkbook (Workbook2.xlsx) now.... but it copies the macro.

Hi Ali,

Thanks for your posting and using Aspose.Cells.

It is a correct behavior. Workbook.Copy() deletes all the settings, sheets and macros of destination workbook and then copy all the settings, sheets and macros of source workbook into destination workbook.

Workbook.Copy() does not combine the workbook but copies the source workbook into another by overwriting the destination workbook.

Hi,


And, if you want to merge two workbooks, kindly use Workbook.Combine() method which does retain the sheets if it works for your requirements.

Thank you.

Hi,

To your comment:

"It is a correct behavior. Workbook.Copy() deletes all the settings, sheets and macros of destination workbook and then copy all the settings, sheets and macros of source workbook into destination workbook."

Correct it doesnt do that anymore, but it did it until version 7.4.1.

Workbook.Combine() does what Workbook.Copy() did before, so I am using this method instead.

Thanks for your help.

/Ali

Hi Ali,

Thanks for your posting and using Aspose.Cells.

It is good to know that you were able to sort out your issue with Workbook.Combine() method and it fits your needs. In case, you face any other issue, please feel free to post on our forum, we will be glad to help you further.