Tobias Knauss
Tobias Knauss

Reputation: 3539

Excel automatically renames back ActiveX controls when reopening XLSM spreadsheet file

I had added an ActiveX control (in my case, it was a ComboBox, but it might as well be a button or something else) to a spreadsheet, and named it Analysis1_FileAction_ComboBox. Later I renamed it to Analysis1_DataFileAction_ComboBox. The name was accepted, the VBA code compiled and executed successfully with the new name.
After closing and reopening the XLSM spreadsheet, the code failed to execute. I found that the button's name changed back to Analysis1_FileAction_ComboBox.

What's wrong here? Why was the control automatically renamed back?

This issue is seen in Office 365 in year 2025, and has nothing to do with missing updates like in earlier versions of Excel.
Also, it happens not on other computers or user profiles, but on every computer.

Upvotes: 1

Views: 24

Answers (1)

Tobias Knauss
Tobias Knauss

Reputation: 3539

I found the solution in https://www.mrexcel.com/board/threads/activex-button-name-wont-save.904018/, and it's related to https://stackoverflow.com/a/40219547/2505186.

The actual problem is: The name of the control was too long!

This is VERY weird because the new name was previously accepted AND used, especially since there is no length limitation in the properties window. I could insert Analysis1_FileAction_ComboBox01234567890123456789012345678901234567890123456789012345678901234567890 (100 chars) for a quick test... and it worked: the code compiled and executed successfully.

BUT... Excel refuses to save the new name when the spreadsheet is saved and closed. It just takes the old name and does not tell about this change!
Therefore, after reopening the XLSM spreadsheet file, the previous name is used for the control.
No failure message, no warning message, nothing.

Analysis1_FileAction_ComboBox has 29 characters, which is within the limits.
Analysis1_DataFileAction_ComboBox has 33 characters, which is out. As I found out, the maximum accepted length is 32 chars.

Upvotes: 2

Related Questions