I tried to use the code in one of the answers before
ActiveWorkbook.SaveAs fileName:="yourfile.xlsx", fileFormat:=51
but the program displayed alert and in this case user must manually react to this alert, so I added additional code lines:
Application.DisplayAlerts = False
With ActiveWorkbook
.SaveAs Filename:=excelReportFilePath, FileFormat:=xlOpenXMLWorkbook ' this enumeration value is the same as 51
End With
Application.DisplayAlerts = True
In this case, code block worked without alert and after formed workbook with copied sheets in which originally were code was closed, and then opened again from its directory, in the copied sheets the code is absent. In this case alert - Programmatic access to Visual Basic Project is not trusted - wasn't thrown as can be on some user PC as in the case when code
' Remove all lines from its code module...
With ThisWorkbook.VBProject.VBComponents(strObjectName).CodeModule
.DeleteLines 1, .CountOfLines
End With
was used.
So the advantage of this way that you don't need to care about security settings in a user PC and about correct copying data from source sheet into the additionally created empty sheet.