Hi
Hi,
Hi Amjad,
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,
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,
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.