You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
Loading a macro-enabled workbook (via wb_load()) with sheet-based VBA macros (such as Private Sub Worksheet_SelectionChange(ByVal Target As Range)) and saving it again using wb_save() results in the removal of those macros from the sheets.
What seems to happen is that openxlsx2 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
Create a Macro-enabled Excel file
Add a sheet-based macro (such as Private Sub Worksheet_SelectionChange(ByVal Target As Range)). This doesn't have to 'do' anything. Save.
View the sheets in the Excel macro view (Alt+F11)
Load the workbook via wb_load()
Save the workbook object via wb_save()
Re-open the workbook in Excel, and examine the sheets in the macro view (Alt+F11)
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.
The openxlsx had the same behaviour.
Screenshots
Example files
I cannot upload macro-enabled Excel files but the problem should be easily reproducable.
The text was updated successfully, but these errors were encountered:
Describe the bug
Loading a macro-enabled workbook (via
wb_load()
) with sheet-based VBA macros (such asPrivate Sub Worksheet_SelectionChange(ByVal Target As Range)
) and saving it again usingwb_save()
results in the removal of those macros from the sheets.What seems to happen is that
openxlsx2
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.wb_load()
wb_save()
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.
The
openxlsx
had the same behaviour.Screenshots
Example files
I cannot upload macro-enabled Excel files but the problem should be easily reproducable.
The text was updated successfully, but these errors were encountered: