Forum Discussion
Excel 365 64-bit: Out of memory when editing VBA in an existing XLSM
Two A/B tests should separate the build from the project, since a new blank workbook already works on this build.
Same build, old file: open the preserved copy that compiled before, on this PC, and type the same Dim line. If it works, the build is fine and something in the current file's VBA project changed. Same file, other build: open the current file on another PC or a different update channel. If it fails there too, it's the project, not the installation.
Microsoft's page for this error (Out of memory, Error 7) says it can also mean a 64K segment boundary was hit, either because a module or procedure is too large or because the project ran out of space for Public variables. Since it happens in every standard module and on a single Dim, compare the current project with the preserved copy: if modules grew a lot or many Public declarations were added since then, that's the likely cause. Splitting big modules and cutting the number of Public variables are the fixes Microsoft lists.
The import test Support suggested also settles it without touching the sheets or CustomXML: export each module, class and form (File > Export File), import them into a new .xlsm, then run Debug > Compile VBAProject and add a test line. Same error there means it's the code itself (size or Public variables). Works there means the problem is in the original file's stored VBA project, and you can remove and re-import the modules in a copy of the original.
For Microsoft, the most useful evidence is the result of those tests plus the first build where the error appeared.
(Drafted with AI assistance and checked before posting.)