ActiveX controls converted to pictures when opening and saving xlsm file

Issue #1160 duplicate
Robin Nandi created an issue

ActiveX controls converted to pictures when opening and saving a macro-enabled Excel file with openpyxl.

Software versions:

  • Windows 8.1 Pro
  • Microsoft Excel 2016 MSO (16.0.9126.2259) 32-bit
  • Python 3.7
  • openpyxl 2.5.12

To demonstrate the issue follow the simple example below:

  • QuickTest.xlsm is a macro-enabled Excel file with a single command button
  • QuickTestSaved.xlsm created using shutil.copy2 is fine
  • test.xlsm created by opening and saving with openpyxl has command button converted to a picture i.e. it does not work as a command button and if you right-click on it you can format image, but not view code
import os.path
import shutil
import openpyxl

path = os.getcwd()

f1 = "QuickTest.xlsm"
f2 = "QuickTestSavedFile.xlsm"

shutil.copy2(os.path.join(path, f1), os.path.join(path, f2))
Pricing_Model = openpyxl.load_workbook(filename=os.path.join(path, f2), read_only=False, keep_vba=True)
Pricing_Model.save('test.xlsm')

Comments (2)

  1. Log in to comment