Where 2 place the code? (Worksheet Codes Vs. Modules)

F

FARAZ QURESHI

Some times some of the macro and code pieces are advised to be placed at the
worksheet code level and sometimes a separate module operates well. What is
the difference between both and how to identify the same?
 
S

Simon Lloyd

FARAZ said:
Some times some of the macro and code pieces are advised to be placed a
th
worksheet code level and sometimes a separate module operates well
What i
the difference between both and how to identify the same
-

Best Regards
FARAZ A. QURESH
It depends on how its written, but as a general rule if i
beginsPrivate Sub Worksheetthen its workshee
code, if it beginsPrivate Sub Workbookit goe
in the Thisworbook module and lastly if it beginsSu
Macroit goes in a standard module and can be prefixed wit
Public or Private

--
Simon Lloy

Regards,
Simon Lloyd
'The Code Cage' (http://www.thecodecage.com
 
S

Shane Devenshire

Hi,

Generally speaking the Sheet and thisWorkbook modules are for event code
related to a specific sheet or thisWorkbook object. When you are in one of
these modules you will notice that you can choose Worksheet or Workbook from
the top left "object" drop down and then a "procedure" from the top right
dropdown. All code associate with these procedures are places in these
modules. In addition ActiveX control have their code here. The "procedures"
found in these modules only work if they are located here, although they can
call code in other modules.

Code can also be placed in Form objects and Class modules as well. Other
code is usually placed in the general modules, but that is not a requirement
in all cases.
 
Top