Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Combining Modules
I have about 40 modules, and it is getting hard to figure out my code.
How can I combine them? I have tried cutting and pasting, and then exporting and deleteing modules, but this leads to different errors, depending on what modules combine. Is there certain stuff in different modules? I would have thought that if I put all of the declarations up at the top, that I could combine them all. Also, what is the flow when I show a form? It seems to call some functions/subs by itself. If I try removing some of the functions, yet I find no referance calling them in the code, I get an error on show Thanks Phil |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Combining Modules
Phillips,
When you Show a form the Initialize and Activate events occur. No other events should run. Having many (well named and well written) modules is probably better than one with thousands of lines of spaghetti code. ***Always comment your code so you can go back and know what its doing.*** If one module calls another (and that is the only caller of the second module) then it might be better to combine them. To clarify: If A calls B (and nothing else calls B) then combine them. Replace the calling line with the code from the called module. Move only the Global declarations to the top of the combine module. HTH Henry "Phillips" wrote in message news:cFcxb.118974$Dw6.547218@attbi_s02... I have about 40 modules, and it is getting hard to figure out my code. How can I combine them? I have tried cutting and pasting, and then exporting and deleteing modules, but this leads to different errors, depending on what modules combine. Is there certain stuff in different modules? I would have thought that if I put all of the declarations up at the top, that I could combine them all. Also, what is the flow when I show a form? It seems to call some functions/subs by itself. If I try removing some of the functions, yet I find no referance calling them in the code, I get an error on show Thanks Phil |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Combining Modules
Phil,
I would recommend that you not combine the modules. First of all, there are limits to the size of a module: convention wisdom holds that a module should not exceed 5000 lines of code or about 64K bytes. Moreover, a well organized project is easier to maintain. You should give your modules meaningful names rather leaving the names Module1, Module2, etc. To rename a module, open it in the VBA editor, press F4 to display the Properties box, and change the name. Each module should contain functionally- or conceptually-related procedures, and the module name should reflect the contents of the module. Also, what is the flow when I show a form? When you show a form with code like Userform1.Show, code execution stop at the Show method, and won't resume until the form is hidden. Code within the form's code module will execute in response to events, such as initializing the form, clicking a control, etc. If your code is executing procedures in standard code modules randomly, you should use Rob Bovey's Code Cleaner to export all the code to text files, purge the VBProject, and import the code back in to the project. This can cure a variety of problems. You can get the free Code Cleaner from the Free Utilities section at www.appspro.com . -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com "Phillips" wrote in message news:cFcxb.118974$Dw6.547218@attbi_s02... I have about 40 modules, and it is getting hard to figure out my code. How can I combine them? I have tried cutting and pasting, and then exporting and deleteing modules, but this leads to different errors, depending on what modules combine. Is there certain stuff in different modules? I would have thought that if I put all of the declarations up at the top, that I could combine them all. Also, what is the flow when I show a form? It seems to call some functions/subs by itself. If I try removing some of the functions, yet I find no referance calling them in the code, I get an error on show Thanks Phil |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
VB Modules | Excel Discussion (Misc queries) | |||
Help with modules. | New Users to Excel | |||
modules | Excel Programming | |||
Class Modules vs Modules | Excel Programming | |||
Copying modules | Excel Programming |