PDA

View Full Version : Solved: Grouping Modules?



aerodoc
10-27-2011, 11:08 AM
I want to integrate several projects into one.

Is there a way to group all of the modules from the different projects in a folder? Otherwise, it will be difficult to see what is associated to what.

The fall back plan would be to do it with a naming convention (project1_mod, project1_mod2, and..project2_mod1, project2, mod2, etc.) but will get messy.

Also, is there a way to separate the modules (from a project) from talking to eachother? For example, I have a lot of subs with the same name (but not identical) amongst the projects I want to integrate. I would have to rename them all, or else they will interfere. Making the sub private won't really help since they still need to talk to eachother amongst the group of modules.

Kenneth Hobs
10-27-2011, 11:39 AM
You have to plan for those collisions. Whatever you do, do not use the same routine name in the same Module. Option Explicit is your friend.

I typically name my Modules in my Personal workbook with a prefix of "m" or "mod" and then the category. e.g. mADO, mRange, mMSWord, etc.

Here is one way to make sure that you call the correct routine. I have 3 Subs named Test in 3 Modules.
Sub Test()
Module1.Test
Module2.Test
End Sub

aerodoc
10-27-2011, 12:00 PM
Ken,

So what I am hearing is that there is no way to "isloate" a group of modules. I did not plan for this (originally this was not an objective), so I will have to go back and rework them.

Your tip will be a time saver, but a follow on question. Will that approach will is the subs are set to private and I and I need to call them from another module?

I would like to make the subs public (easier that way), but if I do then there will be tons of subs that are accessible to the user. Is there a way to not show the subs when the user picks "Tools/Macro/Macros" (2003)? Or must the subs be set to private to prevent that?

Kenneth Hobs
10-27-2011, 12:11 PM
If you are going to make them Private, you should explore using them in a Class.

Otherwise, use Application.Run. e.g.
Application.Run ("'" & ThisWorkbook.FullName & "'!Module1.Test")
Application.Run ("'" & ThisWorkbook.FullName & "'!Module2.Test")

GTO
10-27-2011, 02:18 PM
Hi All,

I may not be understanding what you are wanting to do to Ken's level (actually, that seems very likely in sleep-depravation state), but might not another alternative might be to change the subs to non-returning functions?

Mark

Aflatoon
11-04-2011, 01:41 AM
Add Option Private Module to the top of any module that contains subs you don't want visible in the macros dialog.

Paul_Hossler
11-04-2011, 12:00 PM
I'd use a combination of 'Option Private Module' and 'Public' and 'Private'


'------------------------------- one module
Option Explicit
Option Private Module

Sub TestSub1()
MsgBox "Private TestSub1 in Private Module"
End Sub

Public Sub TestSub2()
MsgBox "Public TestSub2 in Private Module"
End Sub

'------------------------------- other module
Option Explicit

Private Sub TestSub3()
MsgBox "Private TestSub3 in Public Module"
End Sub

Sub TestSub4()
MsgBox "Public TestSub4 in Public Module"
'Call TestSub1 **** non-Public sub in a Private Module is not visible here
Call TestSub2
Call TestSub3
End Sub


TestSub4 is the only one that is exposed to the RunMacros dialog for the user, but the Public sub in a Option Private Module is available to it, as is the Private sub within the same module

Paul

mikerickson
11-05-2011, 07:17 AM
Alternalty, you could add a dummy optional argument to the sub to keep it out of the Macro Dialog box.