Search code examples
excelvbaout-of-memory

I have a workbook with no sheets & I'm getting Out of Memory error when I execute VBA calls


I'll add more details to this question as I do troubleshooting and can narrow down when the problem occurs. But maybe someone will recognize the problem from what I already know and can describe.

  • I have two workbooks open. If I display workbooks.count, it agrees that there are 2 open.

  • If I hover over the taskbar, I see 5 Excel windows (the 2 workbooks, the VBA window, and two empty Excel windows). What I mean -- the empty windows have the ribbon but don't have any worksheet tabs. One of them says that cell O13 is selected. The other says that no cell is selected but the formula bar shows a value of "EM-75." (I can't type in the formula bar.)

  • When I select one of the workbooks that displays data and display activesheet.name, I see the name of the sheet and I also get an error "Out of memory."

  • When I select one of the empty workbooks and display activesheet.name, I get the Out of memory error and nothing displays in the immediate window.

  • Actually, not matter what command I type in the Immediate window, it looks like it runs the command and then gives me the Out of memory error. I can type ?7+2 and I get the answer 9 and also out of memory.

  • One of the workbooks is 370K and the other is 18.2MB. So it's hard to believe I'm running out of memory. I saw a thread that Out of memory may be a default VBA error message for other cases, but I don't know about that.

  • After I close and save the two good workbooks (to SharePoint), the two empty worksheets remain, and the close command is inactive. (The x above the menubar to close the book can be selected but doesn't do anything.) Selecting "Close all windows" from the Windows taskbar has no effect on the two remaining windows.

  • If I select Excel from the taskbar to create a new, empty workbook and then I close that workbook, then the phantom workbooks also close and Excel class.

  • I'm getting the error on a different machine so I don't have screenshots that I can paste. But I can try to get those if no one recognizes this problem and ya'll want to see the empty windows.

  • I have not been successful consistently recreating the error. I thought it might have something to do with opening/closing/saving files with VBA, but I've run through that routine successfully, also. So it seems there must be some other condition involved.


Solution

  • I don’t know why it causes the Out of memory error, but I think I found a way to avoid it. The error appears when I close the last open workbook. I inserted a test for the number of open workbooks. If workbooks.count = 1, then instead of closing the workbook, I quit the application. That has eliminated the problem.