lwildernorva
01-30-2008, 04:27 PM
I did a search on module naming but found nothing quite on point so I thought I'd start a new thread. I have used Word VBA for several years but only recently noticed that the default method of naming modules ("NewMacros", "Module1") seems to violate the general principle of placing clear names in code to help us and others identify what we're doing (e.g., "strHearingSite" instead of "str1").
I also began to realize as some of my projects got larger that there would be advantages to gathering all relevant code in one module. For instance, I have a set of procedures that I use that will insert as text certain percentages and dollar values based on user input, including relevant dates, disability percentages, and wages. Rather than leaving all that code in a "Module1" with other code not related to this set of procedures, I decided I wanted to create an independent module that would allow me to find the relevant code quickly and all gathered into one place. I also realized that such a method would allow me to share the code with others simply by exporting the code in the module to a .bas file rather than by copying all of the code into a text file (which can quickly become a rather large file as you might imagine).
Well, imagine my surprise when I learned that there is no "rename" entry when you right-click on a module. Furthermore, as is frequently the case, Help is of little help in giving you direction--unless you read between the lines. If you enter "Name Module" into the Help query box in VBA, the OrganizerRename method is listed, telling you how you can rename by code. Although you can't name your project as you wish when you start it, in Word, you can use the Macro Organizer to rename the project from "Macro1" to "CompRateCalculators" as I did. You can also open the Project Properties window (F4), and on the alphabetic tab, change the name of the project in this manner.
But as we know, every action has consequences. And in this case, I'm trying to learn whether there are any disadvantages to my approach. I haven't noticed that code runs slower and am unaware that having a number of individually named projects rather than a bunch of code dumped into one module has any other adverse effects. Keep in mind that none of this code resides in the Normal template--I have learned to keep Normal lean and mean.
I guess my question boils down to: are my perceived efficiencies in implementing this method of creating multiple modules within a project and identifying them with individual names offset by any unforeseen inefficiencies?
Hope that this post has provided some useful information as well as generated some ideas.
Lee
I also began to realize as some of my projects got larger that there would be advantages to gathering all relevant code in one module. For instance, I have a set of procedures that I use that will insert as text certain percentages and dollar values based on user input, including relevant dates, disability percentages, and wages. Rather than leaving all that code in a "Module1" with other code not related to this set of procedures, I decided I wanted to create an independent module that would allow me to find the relevant code quickly and all gathered into one place. I also realized that such a method would allow me to share the code with others simply by exporting the code in the module to a .bas file rather than by copying all of the code into a text file (which can quickly become a rather large file as you might imagine).
Well, imagine my surprise when I learned that there is no "rename" entry when you right-click on a module. Furthermore, as is frequently the case, Help is of little help in giving you direction--unless you read between the lines. If you enter "Name Module" into the Help query box in VBA, the OrganizerRename method is listed, telling you how you can rename by code. Although you can't name your project as you wish when you start it, in Word, you can use the Macro Organizer to rename the project from "Macro1" to "CompRateCalculators" as I did. You can also open the Project Properties window (F4), and on the alphabetic tab, change the name of the project in this manner.
But as we know, every action has consequences. And in this case, I'm trying to learn whether there are any disadvantages to my approach. I haven't noticed that code runs slower and am unaware that having a number of individually named projects rather than a bunch of code dumped into one module has any other adverse effects. Keep in mind that none of this code resides in the Normal template--I have learned to keep Normal lean and mean.
I guess my question boils down to: are my perceived efficiencies in implementing this method of creating multiple modules within a project and identifying them with individual names offset by any unforeseen inefficiencies?
Hope that this post has provided some useful information as well as generated some ideas.
Lee