PDA

View Full Version : Solved: putting code on a sheet or module



philfer
01-01-2008, 12:39 PM
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

RichardSchollar
01-01-2008, 12:50 PM
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 :)

Bob Phillips
01-01-2008, 02:20 PM
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.