Inserting a new sheet in middle of the existing sheets of the workbook and trying to add a module for that sheet in vba project. it is removing other sheet vba code

Inserting a new sheet in middle of the existing sheets of the workbook and trying to add a module for that sheet in vba project. it is removing other sheet vba code

workbook.Worksheets.Insert((int)sheetIndex, SheetType.Worksheet, p)
workbook[p].CodeName = “template2”;
workbook.VbaProject.Modules.Add(workbook.Worksheets[p]);

workbook.VbaProject.Modules[workbook.Worksheets[p].CodeName]
.Codes = vbCode;

@taruney,

Thanks for the code segment.

Please provide complete sample code and template file to reproduce the issue. Alternatively you may provide a standalone console demo application (runnable), zip the project and provide us here. Also provide output file for thorough evaluation. We will check it soon.