Closed nicojx closed 9 months ago
Realised this is similar to / the same issue as: https://github.com/ycphs/openxlsx/issues/44.
I have very little programming experience, but happy to try to help resolve it.
@nicojx , you could see if this works with openxlsx2, it's unlikely to be fixed here
Exactly the same behaviour with openxlsx2 -- I'll raise it there, too. Thanks!
This issue is stale because it has been open 365 days with no activity. Remove stale label or comment or this will be closed in 7 days.
This issue was closed because it has been stalled for 7 days with no activity.
Describe the bug Loading a macro-enabled workbook (via
loadWorkbook()
) with sheet-based VBA macros (such asPrivate Sub Worksheet_SelectionChange(ByVal Target As Range)
) and saving it again usingsaveWorkbook()
results in the removal of those macros from the sheets.What seems to happen is that
openxlsx
creates copies of the original sheets without macros (the visible sheet name is the same but the Excel-internal sheet name is different), while the original sheets remain with macro but without the data / invisible. This can then be seen in the VBA view sheet list (see screenshot). Originally only one sheet (Sheet1 was both internal and external name) existed.To Reproduce
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
). This doesn't have to 'do' anything. Save.loadWorkbook()
saveWorkbook()
Expected behavior The same sheets exist after save as before save, with macros attached to sheets. The issue does not appear on non-macro-enabled (xlsx) workbooks. I could not test it on macro-enabled (xlsm) workbooks without macros, as Excel refused to open these after
saveWorkbook()
saved them.Screenshots
Example files I cannot upload macro-enabled Excel files but the problem should be easily reproducable.