VBA, module name , what are the naming convensions?

krish

Board Regular
Joined
May 17, 2005
Messages
211
Hi,

I tried to search MSDN for the naming convension for VBA modules. Couldn't locate any doc. If you know, could you please let me know the msdn link?.

for example, a module name shouldn't start with numbers or * etc.

thanks for the help
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
krish

If you mean what's legal to name a module that's slightly different from a naming convention.

Naming conventions are generally a personal preference.

eg some people will precede each standard module name with mdl or a class module with cls
 
Upvote 0
I searched the VBA help file for "module name" and found a topic of "Visual Basic Naming Rules." Seems like it would be what you want:

Visual Basic Naming Rules

Use the following rules when you name procedures, constants, variables, and arguments in a Visual Basic module:

  • You must use a letter as the first character.
  • You can't use a space, period (.), exclamation mark (!), or the characters @, &, $, # in the name.
  • Name can't exceed 255 characters in length.
  • Generally, you shouldn't use any names that are the same as the functions, statements, and methods in Visual Basic. You end up shadowing the same keywords in the language. To use an intrinsic language function, statement, or method that conflicts with an assigned name, you must explicitly identify it. Precede the intrinsic function, statement, or method name with the name of the associated type library. For example, if you have a variable called Left, you can only invoke the Left function using VBA.Left.
  • You can't repeat names within the same level of scope. For example, you can't declare two variables named age within the same procedure. However, you can declare a private variable named age and a procedure-level variable named age within the same module.
    Note Visual Basic isn't case-sensitive, but it preserves the capitalization in the statement where the name is declared.
 
Upvote 0
Kristy

Isn't that for "procedures, constants, variables, and arguments in a Visual Basic module:"?:)

I tried to find something about naming modules but I couldn't apart form this which I got when I hit Help when I tried naming a module with a number.
Form and control names must start with a letter and can be a maximum of 40 characters — including letters, numbers, and underscores (_).
But that doesn't mention modules.:o
 
Upvote 0
True. I think I read it incorrectly.

Oh well. It isn't going to hurt to know those rules, either :)
 
Upvote 0
Kristy

Nothing wrong with knowing the rules.:)

In fact I'm sure there's a thread on here somewhere that detailed what you could and couldn't use for Sub names.

Mind you I think I need to brush up on my spelling and/or typing.:oops:
I couldn't apart form this
 
Upvote 0

Forum statistics

Threads
1,225,335
Messages
6,184,335
Members
453,227
Latest member
Slainte

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