The aim of my work is just to save multiple Excel Macro files with exactly the same name.
I used the openpyxl library for it. The only thing, which changes in my file is the number att the end.
My code looks as follows:
from openpyxl import Workbook, load_workbook
wb = load_workbook('Collections/Collection Note - 001.xlsm')
ws = wb.active
for x in range(2,25):
newname = "%03d" % x
wb.save('Collections/Collection Note - '+newname+'.xlsm')
Everything works well as the files come out. However, I have no faintest idea why are they corrupted?
What is wrong here, since I want just open them and resave?
>Solution :
The problem is because you are using xlsm files (files with Macro-enable).
In this case youve to load the files differently:
load_workbook('Collections/Collection Note - 001.xlsm', read_only=False, keep_vba=True)
(Btw you could look inside your xlsm files by renaming them to filename.zip and check if there is stuff missing)
