I have hundreds of excel files that need to be extended with code and new sheets. When I add the code first, it saves correctly. Unfortunately the code contains references to the sheets that needs to be added. So I have to add the sheet before… But then the problem occurs, that the added code is not saved within the workbook. Even if added the sheet manually… I’m not able to add code in any way.
Share
The problem was solved when I used
SaveAsinstead ofSaveand provided the file format:The excel file extension doesn’t matter. Worked for me 🙂
Edit:
Also the file extension must match file format. For instance, files saved with
XlFileFormat.xlOpenXMLWorkbookMacroEnabledmust be saved with thexlsmextension. Otherwise, every time on opening the file, a alert message will appear.