Consulting

Results 1 to 3 of 3

Thread: Solved: putting code on a sheet or module

  1. #1
    VBAX Tutor
    Joined
    Nov 2007
    Posts
    291
    Location

    Solved: putting code on a sheet or module

    I have a sheet in a workbook called "Menu" where all the buttons sit for the user to perform the tasks they need.

    When I put a button there and choose view code it opens the code window behind the worksheet "Menu" I have been putting all my code there

    All the Excel VBA books I have read say the code should go in Modules.

    Am I committing a cardinal sin? Will I burn in the eternal fires on VBA hell.

    If I have to put all the code in a Module how can I get the buttons on the Menu sheet to look at the module rather than the code behind the sheet

  2. #2
    VBAX Contributor
    Joined
    Aug 2006
    Location
    Hampshire, UK
    Posts
    140
    Location
    You are putting them in a module - in the worksheet (class) module to be precise. You may find it useful to call subs/functions sat within a standard module from the worksheet module (eg in response to Events) as this then makes it easy for different sheets/objects to call the same code, but you haven't done anything horribly wrong

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Are those forms toolbar buttons on control toolbox buttons? If the latter, the click triggers a worksheet event, so the code needs to be in the worksheet code module. If the former, you just assign macros to that button, and they should be in a general code module.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

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