Does VBA have a 64K limit on Modules?
Does VBA have a 64K limit on Modules?
(OP)
These fora contain occasional references to a size limit of 64K for a VBA module in Excel (the most recent being thread766-279070: Microsoft Office Excel has stopped working..). Over the years I have also come across similar mentions elsewhere in CyberLand.
To try to sort this out once and for all, I have just searched Google Groups. Among the more believable posts I came across was the following one, on eggheadcafe.com, by the widely-respected Chip Pearson on 14th March 2010.
» Whether it does in fact exist, or is merely some sort of e-urban myth;
» Exactly what the limit applies to;
» Which versions of Excel it applies to;
» How one determines how close one is to the limit;
» What happens when the limit is exceeded.
To try to sort this out once and for all, I have just searched Google Groups. Among the more believable posts I came across was the following one, on eggheadcafe.com, by the widely-respected Chip Pearson on 14th March 2010.
Does anyone have any definitive knowledge about this supposed 64K limit? Useful facts would include:Quote:
The 64K limit is on the size of "compiled" code, not the size to the text source code. (VBA code is never stored as text within the workbook. It is stored in an intermediate byte-code language called OpCodes -- similar in theory to Java -- and at runtime or when you choose Compile from the Debug menu, VBA converts the OpCodes, which are version/platform neutral, to ExCodes, which are version specific and feeds those ExCodes to the VBA interpreter runtime which executes machine code on behalf of VBA based on the ExCodes. What you see on the editor screen as text code is the OpCodes translated to text for display.)
Exporting the module to a text file and looking at the size of that file might give you a crude approximation of the compiled size, but I would not give it much credibility. As far as I know, the 64K limit is not publicly documented. It was revealed to an MVP by a Softie and has propagated via usenet.
» Whether it does in fact exist, or is merely some sort of e-urban myth;
» Exactly what the limit applies to;
» Which versions of Excel it applies to;
» How one determines how close one is to the limit;
» What happens when the limit is exceeded.
RE: Does VBA have a 64K limit on Modules?
All I can say is that I have had problems (of the random crash variety) when using large modules, and splitting them into smaller sizes appears to have helped. Due to the nature of these things I can't guarantee that this isn't "confirmation bias" at work, but I don't think so.
If I think a module may be getting too big I just split it; nothing scientific I'm afraid.
I have just checked the ALGLIB library, and the biggest module in that is 183 kB when saved as a text file. That seems to run without any problem, but it contains a large proportion of comments in the text, so the opcode size is presumably much smaller.
Doug Jenkins
Interactive Design Services
http://newtonexcelbach.wordpress.com/
RE: Does VBA have a 64K limit on Modules?
=====================================
(2B)+(2B)' ?
RE: Does VBA have a 64K limit on Modules?
=====================================
(2B)+(2B)' ?
RE: Does VBA have a 64K limit on Modules?
http://www.tek-tips.com/threadminder.cfm?pid=707
=====================================
(2B)+(2B)' ?
RE: Does VBA have a 64K limit on Modules?
But no clue how to check the size of either.
=====================================
(2B)+(2B)' ?
RE: Does VBA have a 64K limit on Modules?
I recently came across the following URL which refers to Visual Basic Code limitations.
http://msd
From what I have read (As an example):
ht
http://www.avdf.com/nov96/ts_vba.html
http:
it is my understanding that VBA is based on VB, so this is the most "official" definition I have seen.
RE: Does VBA have a 64K limit on Modules?
"Module too big" in writing VBA code seems to be a bit like "teething" in child rearing. It gets blamed for all sorts of problems, when in fact all learned studies conclude that there is no correlation whatsoever.
RE: Does VBA have a 64K limit on Modules?
I'm not really convinced by the "learned studies" in either case, but surely it's a good idea to keep modules to a moderate size anyway.
Doug Jenkins
Interactive Design Services
http://newtonexcelbach.wordpress.com/