.

Issue | Solved - Excel VBA Out of stack space {Error 28}

Stack is a memory that is allocated to executing program to store variables and function calls. It grows and shrinks dynamically. 

You may face an error stating "Out of stack space" in a vba program due to some reasons. There may be multiple reasons and all those lead to overflow of stack memory. Once it is full, it throws this exception.

Solution:
As such, there is no magical stick that will grow the stack memory. And you need to follow some rules to avoid them.


1. Avoid Recursion or handle gracefully

Most of the times, this error is observed due to recursion. make sure that recursive calls terminate properly.


2. Local variables require more space than available.
You may avoid some variables at sub-procedure or function level, rather declare them at module level.


3. Avoid too many nested DoEvents
DoEvents let processor do the stuff when our program is busy for some IO. It creates some sort of multithreading. Nesting it too much creates this exception.

No comments :

Post a Comment

Recent Posts