Too many local, nonstatic variables

This page is specific to the Visual Basic for Applications (VBA) Language Reference for Office 2010.

Local, nonstatic variables are variables that are defined within a procedure and reinitialized each time the procedure is called. This error has the following cause and solution:

  • The sum of the memory requirements for this procedure's local, nonstatic variables and compiler-generated temporary variables exceeds 32K. Declare some of your variables with the Static statement where appropriate. Static variables retain their value between procedure invocations because they are allocated from different memory resources than nonstatic variables.

For additional information, select the item in question and press F1 (in Windows) or HELP (on the Macintosh).