Consulting

Results 1 to 8 of 8

Thread: Solved: Grouping Modules?

  1. #1
    VBAX Regular
    Joined
    Oct 2010
    Posts
    85
    Location

    Solved: Grouping Modules?

    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.

  2. #2
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    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.
    [VBA]Sub Test()
    Module1.Test
    Module2.Test
    End Sub[/VBA]

  3. #3
    VBAX Regular
    Joined
    Oct 2010
    Posts
    85
    Location
    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?

  4. #4
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    If you are going to make them Private, you should explore using them in a Class.

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

  5. #5
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    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

  6. #6
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,720
    Location
    Add Option Private Module to the top of any module that contains subs you don't want visible in the macros dialog.
    Be as you wish to seem

  7. #7
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,728
    Location
    I'd use a combination of 'Option Private Module' and 'Public' and 'Private'

    [VBA]
    '------------------------------- 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
    [/VBA]

    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

  8. #8
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    Alternalty, you could add a dummy optional argument to the sub to keep it out of the Macro Dialog box.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •