Forum Discussion

WalmirLuz's avatar
WalmirLuz
Copper Contributor
Oct 27, 2026

Excel 365 64-bit: Out of memory when editing VBA in an existing XLSM

Hello,

 

Microsoft Support referred me to this community because they could not resolve an Excel VBE editing issue.

 

Environment:

  • Microsoft 365 Excel for Windows, 64-bit;
  • Version 2610, build 16.0.20527.20088;
  • Existing macro-enabled workbook (.xlsm);
  • Calculation mode: Manual.

 

Problem:

 

While editing an existing standard VBA module, typing: Dim testeCompilacao As Long and pressing Enter triggers “Out of memory.” Adding a new procedure also triggers the error. This occurs before compiling or executing any macro.

 

In a new blank workbook, I can create a VBA procedure normally.

 

Tests already completed:

 

  • Office Quick Repair: the error persists;
  • Excel Safe Mode: the error persists;
  • Checked VBA references: none marked MISSING;
  • Tried another existing standard module: the same error occurs.

 

A preserved version of the workbook previously compiled successfully and opened without a repair warning.

The workbook contains 46 worksheets, 12,485 formulas, VBA and CustomXML used to persist scenario data. These elements must be preserved during troubleshooting.

Support suggested importing native module exports into a separate new XLSM, without copying worksheets. That isolation test has not yet been completed.

What diagnostic steps can distinguish an Office/VBE build or installation issue from a problem within this specific VBA project? What logs or additional evidence would help identify the cause?

I can provide screenshots of the error and the Excel version. The complete workbook contains proprietary code and data and is not suitable for public posting.

 

Thank you.

2 Replies

  • JKPieterse's avatar
    JKPieterse
    Silver Contributor

    Perhaps the VBAProject has a corruption of some sort. Right-click each module in turn and choose "Export". Save it. Then right-click again and choose Remove module (click No to export as that was already completed)

    Save the file, close it and re-open it.

    Right-click the project in the VBE and select Import. Import the saved module(s). Now try again.

  • 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.)