This problem -may- have started around when I switched from Office 2019 to 365, however I've been doing so much upgrades lately (windows 11, server 2022, etc) that my memory is foggy.
Over the past 6 years, I have developed a plethora of Macro-Enabled excel sheets, most of which are templates that get duplicated for various projects. All of these files have their code password protected (Tools > VBAProject Properties > Protection > Lock project for viewing) They are all located on a central file share (We'll call it "\FileShare"). This location has been added to the Trusted Locations for years now ("Allow Trusted Locations on my network" = true, "Subfolders of this location are also trusted" = true).
I started having issues at first where seemingly random files would start getting "corrupted" or getting "Catastrophic Error" pop ups when trying to run macros, or save the file. I've found optimal work arounds for these:
- Adding "AccessibilityCplAdmin 1.0 type Library" to references
- Files > Options > Trust Center > Trust Center Settings > Macro Settings > Trust Access to the VBA project object model = True
- And in some cases, exporting the code modules, and creating a template from scratch.
However, there are a handfull of "overview" spreadsheets that I have auto-update (run a macro) every night through Task Manager. This is done through some simple VB script files that are called via cscript. Maybe 1-2 times a week, 1 or more of these files fails to run overnight. I then go to open the file, and find that all the Modules are still there, but clicking them reveals not code. I also found that attempting to run a macro freezes the file. Additinally, attempting to add a module freezes the file.
the only workaround I've found is to move the file to a non-trusted loction (desktop), open the file, open VBA window, unlock the macros, debug>complie code, save file, and move back to the \FileShare. I've even noticed when doing this, when moving the file back over, the file size always increases (like it suddenly "added back" the VBA code). however, this is not a permanent fix, and I've found the issue keeps reoccuring. And it's just frustrating that something that has been working without fail for years now, suddenly decides to start having issues.
I've tried re-installing Office. I've even taken a spare Desktop and migrated EVERYTHING to it just to make sure it wasn't a machine-specific issue. Problems still happening.
If this is the "new normal" for me, so be it. But I'd at least like to figure out WHY.
EDIT (03/13/24)
I now remember that the issue started when I switched from using x32 Excel to x64 Excel. The accepted answer addresses this exactly.