That is, add a worksheet to the workbook, and then move out of the workbook to a new workbook, and copy the code of one module of the workbook to the new workbook before moving out. Here is the key code:
'====================================================================== 'Each class list is saved as a single XLS fileActivesheet.moveChDirMyPath'Ignore dialog box, overwrite saveApplication.DisplayAlerts =False 'class name increase "examinee number Processing" VBA module DimIcodelines as Integer DimSCode as StringIcodelines= ThisWorkbook.VBProject.VBComponents ("each class exam number processing"). Codemodule.countoflines'get the number of lines of code in the moduleSCode = ThisWorkbook.VBProject.VBComponents ("each class exam number processing"). Codemodule.lines (1, Icodelines)'get the 1th to Icodelines line codeActiveWorkbook.VBProject.VBComponents.Add (vbext_ct_StdModule). Name="each class exam number processing" 'Add "class number Processing" module to the new fileActiveWorkbook.VBProject.VBComponents ("each class exam number processing"). Codemodule.addfromstring SCode'Add the "ThisWorkbook" module code to the ActiveWorkbook moduleActiveWorkbook.SaveAs Filename:=mypath &"\ Level 2017"& Dickey & Classteacher &". xls", Fileformat:=xlexcel8'save File as Version 2003 (XLEXCEL8) XLS fileActivewindow.close
Copy the "Class number processing" module to a new workbook
Original File Download
Excel VBA inserts VBA module code from this workbook in the worksheet that generated the copy