I tried to use the code in one of the answers before
ActiveWorkbook.SaveAs fileName:="yourfile.xlsx", fileFormat:=51
but the program showed a warning, and in this case, the user must manually respond to this warning, so I added additional lines of code:
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, the code block worked without warning, and after the formation of the workbook with the copied sheets in which the code was originally, it was closed and then opened again from its directory, the code is not in the copied sheets. In this case, the warning - Programmatic access to the Visual Basic Project is not trusted - is not issued, as it may be on some user PCs, as in the case when the code
' Remove all lines from its code module... With ThisWorkbook.VBProject.VBComponents(strObjectName).CodeModule .DeleteLines 1, .CountOfLines End With
was used. Thus, the advantage of this method is that you do not need to worry about the security settings on the user PC and about correctly copying data from the source sheet to an additionally created blank sheet.
source share