Results 1 to 10 of 10
  1. #1
    5 Star Lounger
    Join Date
    Oct 2001
    Location
    San Bernardino, California, USA
    Posts
    734
    Thanks
    0
    Thanked 0 Times in 0 Posts

    VBA Modules (VBA)

    1. What is the difference between a module and a project?

    2. My meager experience has been writing VBA for Excel and I have found that I can have multiple subs within the same module so what is the advantage or reason to have multiple modules? Are there any disadvantages?

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: VBA Modules (VBA)

    1. In Excel, the entire workbook is the project, it can contain many modules. Similarly, a Word document, a PowerPoint presentation and an Access database are projects.

    2a. Developers use modules to organize their code into units that contain procedures and functions that are related to each other. If you have 500 functions and procedures, you'll have to do a lot of scrolling if you store them in a single module. Moreover, the first time a function or procedure is called, the entire module that contains it is loaded into memory, so it makes sense to create several smaller modules.

    2b. There are different types of modules: beside the "standard" module that you probably know, the workbook as a whole (ThisWorkbook) and the individual worksheets each have their own module; if you create a UserForm, it will have a module too, and then there are class modules that you can use to create new objects with their own properties, methods and events. Similar observations hold for Word, PowerPoint and Access.

  3. #3
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: VBA Modules (VBA)

    In addition to the points made by Hans, you can export a module to a .bas file and then import it neatly into another project. If you group functionally related procedures/functions together in modules, this sharing (among your own projects and with your colleagues) becomes a bit less ad hoc.

  4. #4
    Star Lounger
    Join Date
    Jan 2003
    Location
    San Francisco, California, USA
    Posts
    93
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: VBA Modules (VBA)

    Hi Hans,

    I've tried organizing my code into different modules, and what I find is that the size of my template gets too large. Why is this? Is there something I'm doing wrong?

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: VBA Modules (VBA)

    You should be able to get a large amount of code into a template, but Word doesn't always clean up after itself, so size may increase more than is necessary.

    See Combatting Template Bloat on the Word MVP site. You can download a "code Cleaner" there.

  6. #6
    Lounger
    Join Date
    Jun 2002
    Location
    Toronto, Ontario
    Posts
    45
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: VBA Modules (VBA)

    Is there a way to rename the Modules so that they are more informative?
    eg.,
    Module1 to UpdatingModule

    John

  7. #7
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Vienna, Wien, Austria
    Posts
    5,009
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBA Modules (VBA)

    Go to the Properties Window in the VB Editor. It should be on the left hand side, below the Project Explorer. Otherwise, click {F4} to activate it. The first roperty should be Name. Click in the right box, next to Name, and change it from Module1 to anything you like. The prefix "mod" (without the quotes) may be helpful for future reference.
    Gre

  8. #8
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: VBA Modules (VBA)

    Hello Hans
    The page you point to states;
    <hr> It will work with Word 97, Word 2000 and Word 2002. <hr>
    Are you aware of any pitfalls in using it with Word 2003?

    T.I.A.
    Regards
    Don

  9. #9
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: VBA Modules (VBA)

    It works without problems in Word 2003 too. They just forgot to update the page.

  10. #10
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: VBA Modules (VBA)

    <img src=/S/thankyou.gif border=0 alt=thankyou width=40 height=15>
    Regards
    Don

Posting Permissions

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