Adding module for VBAProject does not work

Hi,
we have a problem with adding a new VBA module to an existing dotm document.
It works fine, if document has already an VBA module. But it does not work if dotm has none modules.
To reproduce the problem, i have added the source code and the dotm file.
Example.zip (26.1 KB)
Thanks a lot!

Best regards
Matthias

@curmas

Könnten Sie bitte mehr Informationen über den verwendeten Code und die spezifischen Schritte, die Sie unternommen haben, um das Problem zu reproduzieren, bereitstellen?

To reproduce the problem, i have already added the source code and the dotm file.

@curmas Unfortunately, I cannot reproduce the problem on my side. I used your code for testing:

Document doc = new Document("C:\\Temp\\in.dotm");
VbaProject vbaProject = doc.getVbaProject();

if (vbaProject != null)
{
    System.out.println("vbaProject: " + vbaProject.getName());
}
else
{
    // Create a new VBA project.
    VbaProject project = new VbaProject();
    project.setName("AsposeProject");
    doc.setVbaProject(project);
}

// Create a new module and specify a macro source code.
VbaModule module = new VbaModule();
module.setName("AsposeModule");
module.setType(VbaModuleType.PROCEDURAL_MODULE);
module.setSourceCode("' Test VBA code");

// Add module to the VBA project.
doc.getVbaProject().getModules().add(module);

doc.save("C:\\Temp\\out.dotm", SaveFormat.DOTM);

// Open the output and check
Document doc1 = new Document("C:\\Temp\\out.dotm");
VbaProject vbaProject1 = doc1.getVbaProject();
if (vbaProject1 != null)
{
    System.out.println("vbaProject: " + vbaProject1.getName());
    for (VbaModule m : vbaProject1.getModules())
        System.out.println("code: " + m.getSourceCode());
}

Also, in your attached output document the VBA project is present. Could you please elaborate the problem?

H Alexey,
ok, you are right - the macro module with name “AsposeModule” really exists if i check it with your code.
Unfortunateley i see nothing in the VBA editor, as you can see in the screenshots of attached file.
Do you see the macro module in yout VBA editor?
Maybe you have any ideas why it is not shown on my side.
VBA Views.docx (36.8 KB)
Thanks a lot
Matthias

@curmas You are saving the output as template, try saving the output as DOCM document. In this case the project is properly shown: