Aspose Words when trying to copy module to existing vbaProject remove vbaProject from template

I am facing issue while merging two vba project from 2 different word templates.
I have 2 files 1) Master template (.docm) 2) custom template (.docm)

  1. Master template have 1 form and 2 module code
  2. Custom template have 2 modules.

I want to merge vba code so that I can get all modules and forms in 1 template file.

        using (MemoryStream memoryStream = new MemoryStream(CustomFileWithMacros, false))
        {
           Document _doc = new Document(memoryStream);
        using (MemoryStream memoryStreamMaster = new MemoryStream(MasterFileWithMacros, false))
        {
            Document baseWorkbook = new Document(memoryStreamMaster);

            VbaProject vba = _doc.VbaProject.Clone();
            // this will copy all vba code to custom template file
            _doc.VbaProject = baseWorkbook.VbaProject.Clone();

            VbaProject project = _doc.VbaProject;
            // copy all custom modules to custom template again so that vba code get merged
            foreach (VbaModule vbaModule in vba.Modules)
            {
                if (vbaModule.Type == VbaModuleType.ProceduralModule ||
                        vbaModule.Type == VbaModuleType.ClassModule)
                {
                    VbaModule mod = vba.Modules[vbaModule.Name].Clone();
                    project.Modules.Add(mod);
                }
            }
          }
        }

Thanks in Advance

@ajit.v.surana

Could you please ZIP and attach your input documents, problematic and expected output documents here for testing? We will investigate the issue and provide you more information.

Hi,

Attached contains sample where I want to merge 1-MasterTemplateDocument.docm and 2-SourceToMeage.docm file and expected that all macros from both files to be get copied properly to third file.

Expected - 4-ExpectedMergedDocument.docm

But when trying using above code it results not VBA project in output file.

Actual output - 3-MergedDocumentUsingAspose.docm

Sample.zip (61.9 KB)

Thanks

@ajit.v.surana

We have tested the scenario and managed to reproduce the same issue at our side. For the sake of correction, we have logged this problem in our issue tracking system as WORDSNET-22541. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

Is the issue resolved I can see the status is closed WORDSNET-22541 ---- Status : Closed

@ajit.v.surana

Yes, this issue has been resolved and its fix will be available in the next version of Aspose.Words i.e. 21.9. We will inform you via this forum thread once new version of Aspose.Words is released.

The issues you have found earlier (filed as WORDSNET-22541) have been fixed in this Aspose.Words for .NET 21.9 update.