+ Reply to Thread
Results 1 to 3 of 3

When to code in the different modules

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    12-15-2009
    Location
    Herndon, VA
    MS-Off Ver
    Excel 2010
    Posts
    163

    When to code in the different modules

    In the VBA Editor, there are 3 types of modules (I think that is the term) where you can write your code.


    1. There is a module for each worksheet tab
    2. There is a module called "ThisWorkbook"
    3. Under the folder called "Modules" you can insert new modules.

    ----------------------------------------------------------------------------------------------------

    Please answer each question:

    1. How do you know when to use each type of module?
    2. When is it best to use each module?
    3. Are these modules there to divide up your code into logical blocks to improve understanding and readability for anybody who may need to review your code?

  2. #2
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: When to code in the different modules

    my basic understanding of it

    under module you create functions/sub-routine that you will trigger manually (ie macro)

    Worksheet triggers based on events on sheet level
    ie worksheet change

    workbooks triggers based on workbook level
    ie workbook beforesave/open
    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

  3. #3
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: When to code in the different modules

    There are 2 types of modules, Objects (which include things like ThisWorkbook, Sheets, Userforms and Classes) and standard modules.

    Objects contain code that relates to them and they can respond to events, so they contain subroutines that run when events fire, like a selection changing in a sheet, or the worksheet changing in a workbook, or a control on a userform etc....

    Modules are simply containers for code; so your code will go in here unless it relates to a particular object.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. delete modules of code
    By khalid79m in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-21-2008, 10:58 AM
  2. Spreadsheets with code modules
    By colofnature in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-26-2006, 11:55 AM
  3. [SOLVED] Modules and code
    By Metrazal in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-24-2006, 09:28 AM
  4. [SOLVED] Changing code Modules, PLEASE HELP!!
    By Brett Smith in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 01-31-2006, 09:40 AM
  5. [SOLVED] VBA Code to Import VBA Modules
    By Jeff in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-02-2005, 04:06 PM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1