Word VBA Editor Compile and Crashing on Reset Problems

Ian Lauder 21 Reputation points
2023-05-18T21:35:58.7366667+00:00

This is an issue that has been plaguing me for many months.  It’s on a Word document with a VBA macro that I’ve been working on for literally about 20 years on all versions of Windows and editions of Word over those years.  And it’s only recently this has started being a problem with the VBA system itself. I'm not sure if I just started hitting a limit with the size of my project or if its something else.

I frequently get an “Unexpected error (35010)” error randomly when compiling my project.   Many times, I must close the Word document and reopen it to get it to compile properly.   Sometimes if I wind up doing a few code changes it will start compiling again without errors without having to restart.

I get this seems like an internal memory issue with Word and the only resolution I’ve ever found so far is that increasing the virtual memory resolves it.  But it’s not in my case.   I’ve increased my virtual memory a couple times now and have my Initial size (MB): 15000 and Maximum size (MB): 30000

 

My last try was at what I saw recommended which was 8000 and 15000.

Running Windows 11 Pro 22H2 current build 22621.1702

16GB ram.

 

I’ve also exported all the modules and forms to text files to check the sizes.  Most are very small in the low KB range.  A few were up to about 600kb.   I’ve broken most of those up now into smaller modules but that isn’t helping. 

I have 330 forms (100 of those are just simple message screens with 3 subs and are about 20kb each).  I am working on eliminating most of those help forms into a single data driven form hoping that reducing the # of forms may help.  A few forms are between 400-500kb, a few are around 100 and the bulk are 50kb or less.

I have 61 modules, about 8 of them are in the 200kb range, about 10 in the 100kb and the bulk are in the 30-60kb range.

The 2nd issue and I’m not sure if they are related or not and this is a problem that has only been occurring for about the same amount of time that was never a problem for the first 20 years working on this code base.

The Word VBA editor has started terminating Word frequently when I click the “Reset” button to stop the execution of the macro.   Many times, I also close the Word document when I’m done, and it will hang up for a while before it closes then reopens.   Many times when I go to open the Word document it will fail to open.

Most of the time in these cases it will then want to open in Safe Mode, and usually I must delete the saved copies.  Close the safe mode window.   Sometimes I can get my document opened back up after a couple more tries.  It usually first opens a recovery document or asks if I want to recover the data.  There are 3 or 4 variations of what It winds up doing or asking.  After a few rounds of opening and closing I will either get my document open or it is completely unusable and cannot be recovered or opened in Word 365.

When this happens, I must go over to an older computer running Word 2010, open the document which opens just fine every time, save it.  Then I can go back to my main computer, and it takes 2 or 3 rounds of opening, deleting recover stuff/safe mode, but then it will finally open, and I can start working again.

This is getting frustrating enough I really need to figure out what is going on with the VBA editor.

I have uninstalled and reinstalled Office multiple times, it’s always patched to the most current version, but nothing is helping.

I did turn off Autorecover in the Word Save options because I don’t want all the autorecovery to kick in but there is something that is saving something somewhere that prevents me from just reopening my document on the same computer.  The Word file itself seems to be fine as I can always open it on another computer using Word 2010 when its unrecoverable on my development computer and resaving it on another computer makes it work again on my dev computer.

Does anyone have any other suggestions?

Microsoft 365
Microsoft 365
Formerly Office 365, is a line of subscription services offered by Microsoft which adds to and includes the Microsoft Office product line.
4,328 questions
{count} votes

6 answers

Sort by: Most helpful
  1. VasimTamboli 4,785 Reputation points
    2023-05-19T06:37:28.54+00:00

    It seems like you're experiencing some persistent issues with the Word VBA editor and your VBA project. Debugging such issues can be challenging, but here are a few suggestions that might help you troubleshoot the problems:

    Compact and repair your Word document: Corruption in the Word document itself could be causing the unexpected errors and instability. Try compacting and repairing the document by following these steps:

    • Create a backup copy of your Word document.
    • Open a blank Word document.
    • Go to the "File" tab, click on "Options," and then select "Advanced."
    • Scroll down to the "General" section and check the box that says "Confirm file format conversion on open."
    • Close the options dialog.
    • Open the problematic document. It should prompt you to confirm the file format conversion. Confirm it.
    • Save the document with a different name and test if the issues persist.

    Split your VBA code into separate projects or modules: It's possible that the size and complexity of your VBA project are causing issues with the VBA editor. Consider breaking down your code into separate projects or modules to reduce the overall complexity and make it more manageable. This approach can help isolate potential issues within specific modules and make debugging easier.

    Use error handling: Implement robust error handling in your VBA code to catch and handle any unexpected errors. This can help prevent the VBA editor from crashing and provide more information about the errors that occur. Make sure you have error handlers in place for all critical sections of your code and consider logging error details for further analysis.

    Optimize your code: Review your VBA code for any inefficient or redundant code that could be causing performance issues. Look for areas where you can optimize loops, minimize the use of memory-intensive operations, and ensure proper memory management, especially if you're working with large datasets or complex calculations.

    Check for conflicts with other software: Sometimes, conflicts with other software or add-ins can cause issues with the VBA editor. Temporarily disable any third-party add-ins or security software that may be running in the background and interfering with Word's functionality. Test if the issues persist in a clean environment to identify potential conflicts.

    Consult the Microsoft community and support: If the above steps don't resolve the problems, it might be beneficial to seek assistance from the Microsoft community forums or contact Microsoft support directly. They can provide more specific guidance and troubleshoot the issues based on your specific environment and circumstances.

    Remember to always backup your files before making any significant changes or attempting troubleshooting steps.

    1 person found this answer helpful.

  2. Ian Lauder 21 Reputation points
    2023-05-19T14:22:58.3633333+00:00

    The confirm file format conversion on open doesn't do anything. After opening a new Word doc and checking that option, closing the new doc. Opening the one with my macro it just opens normally and doesn't prompt for anything.

    Since I just resaved the problematic document yet again this morning. Last night when I was done working I had saved the document without issues. This morning double clicking my macro enabled document it didn't open the first time (when this problem happens opening the file the first time doesn't do anything at all, no file opens, no prompts/messages). Then the 2nd time you double click it when it asks you for safe mode and then it eventually gets to where it won't open at all and that's when I have to open it on a 2nd computer. Note I'm using a 2nd PC running Windows 10 and Word 2010 on a network so I'm opening the exact same file that is failing to open on Word 365 on a Windows 11 PC. I'm not opening a copy. It always opens perfectly on Word 2010 and I just compile it and save it. Then I can open it again on the Windows 11/Word 365 PC.

    So, I assume that option to confirm the conversion is supposed to be checking the compatibility mode of the document since I was saved in Word 2010 and converting it to Word 365. I do that manually frequently already and that has never made a difference in the problem reoccurring.

    0 comments No comments

  3. Ian Lauder 21 Reputation points
    2023-05-30T17:55:20.6633333+00:00

    A little progress. Made 3 changes.

    1. Found a WinZip COM add-in in Word that snuck itself into my system and removed it.
    2. I exported all my forms and modules, started a new doc from scratch, reimported everything, reset my references, etc.
    3. Removed about 20 small forms (just simple help popups) and cut down the largest modules/form code sizes only one is about 400k now down from about 600k.

    In the last week I have not had any issues with Word terminating when clicking the reset when debugging.

    I have had a handful of the “Unexpected error (35010)” errors when compiling and it is happening on 2 computers. One a relatively new Surface Pro and the other my main dev PC. Closing and restarting Word resolve those as it always has. Still, I can't have this happening when the next version of the product is released as it happened once when just opening the doc and running the macro on another PC, didn't even open the VBA editor.

    And only 1 time have had to reopening it on the Word 2010 when it wouldn't open after opening in safe mode. Much better than multiple times a day. But there is still something wrong going on with VBA. I have cranked up my virtual memory settings to 30,000 and 60,000.

    0 comments No comments

  4. David Giambruno 0 Reputation points
    2023-06-16T00:55:59.6966667+00:00

    I'm running into the same exact thing, in a variety of environments, with macro templates (.dotm) that have been fine for five to ten years or more.

    I found a quick fix: if I open the template in Office 32 BIT, compile and save, and then it works again (in Office 64 bit). It seems something is wrong with the compiler.

    0 comments No comments

  5. Ian Lauder 21 Reputation points
    2023-06-16T03:03:48.4533333+00:00

    Yea, I'm doing that a lot. My problems went away for the most part for about a week after rebuilding the entire document from scratch and exporting/importing all the modules and forms. The 35010 errors are less frequent but still happen now almost daily. I have deleted a bunch of forms, and broken up all the large modules and forms as well. It doesn't seem to matter having increased the page file size either. And I don't have any 3rd party COM add-ins.

    I almost daily still get the problem where I double click the Word document with the macro that opened fine previously. But nothing happens on the double click (no errors, no document opens, no response at all). Then the next time I try to open it I get the safe mode question and doesn't matter if I open in safe more or not. The document won't open and if it does start to open it just closes. Its impossible to get it to open anymore. The only solution has been to then open it on a 2nd computer in Word 2010, do a compile and save then copy it back to the dev computer. Then go through about 3 rounds of safe mode questions, deleting recovery files, having it open as a new document name then have to close that. Then finally it opens correctly and I can work normally till the next time it happens.

    Extremely frustrating. Plus since it compiles the macro whenever the document is open apparently it can cause a 35010 error on other computers and I have to just close it and reopen it and 2nd try it always works. Which is going to be problematic if it can't get resolved by the time I have to release this to my customer base.

    I haven't seen any problems when opening the document or running it on Word 2010.