Excel VBA Module Name Length Limit

fred3

New Member
Joined
May 1, 2011
Messages
39
I keep reading that Excel VBA: Module names are limited to 255 characters. But, after having some trouble with Module names, I did some testing. Per my empirical testing on both 32-bit and 64-bit installations of Excel, I observe that:
Excel VBA: Module names are limited to 31 characters.

IF a "character" is 8 bits, which would be common in many systems, then:31 characters is 248 bits and 32 characters is 256 bits. So, if the real limit is 255 bits then 31 characters would work and 32 characters would not work.
Here are the names that I tested:
A234567890123456789012345678901
A2345678901234567890123456789012

Might this be the case? I've not found any mention of this possibility including using ChatGPT 4.0.
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Module.Name property documentation suggests that the max length is 64 characters but your findings suggest that it is 32.
Haven't been able to find anything to pin it down one way or the other, but it's one of those things I think about for a second then think "why does it matter?". I'm all about keeping things short and would never have to worry about that, or most, limits.
 
Upvote 0
Module.Name property documentation suggests that the max length is 64 characters but your findings suggest that it is 32.
Haven't been able to find anything to pin it down one way or the other, but it's one of those things I think about for a second then think "why does it matter?". I'm all about keeping things short and would never have to worry about that, or most, limits.
Hmmm that’s interesting re Module.Name docs. I have only found 255 as max. but not in that source. My conclusion is 31 chars.
I can understand and appreciate a bias to “shorter”. Yet, knowing the real specs can save development and testing time. We’re all used to that I’m sure.
If you think that it’s 255 chars then I understand “”why worry” but when I stumbled into “31” with no available supporting information, then it became important. That seems a good reason to want to know and to be more cautious.
Nobody has confirmed this finding so far and that is concerning.
 
Upvote 0
It has always been my style to minimize the length of object names as much as is practical in order to reduce typing. I've probably never exceeded 15 characters for a module name. At this point, we seem to have proved the limit is currently 31 despite what documentation says. Personally I would just take that as the limit and go with it, but that's just me.
 
Upvote 0
The module name is limited to 31 characters, per the VBA spec. A module is not an access object, nor a control.
 
Upvote 0
MARK858: Thank you!
I'm not sure how one would have figured this out. - without the framework being in your head. One reason is that 255 characters is so prevalent on the web in general for this - so web searches aren't very helpful - or weren't for me this time!
Thanks again!!
 
Upvote 0

Forum statistics

Threads
1,223,892
Messages
6,175,236
Members
452,621
Latest member
Laura_PinksBTHFT

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top