View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Frank Kabel Frank Kabel is offline
external usenet poster
 
Posts: 3,885
Default Macro, Module, function, sub and This workbook and sheets ?

Hi
some starting points:
http://www.mvps.org/dmcritchie/excel/getstarted.htm
for macros in general.

ThisWorkbook and the worksheet modules are used for event procedures.
See:
http://www.mvps.org/dmcritchie/excel/event.htm
http://www.cpearson.com/excel/events.htm

Now to your questions:
1. See the first link
2. Normal macros are added to a standard module. Only event procedures
go to the other modules.
3. Public / private: Public functions/variables can be accessed from
the outside of this module, private functions/subs not
4. See event procedures
5. Modules store macros whether they are recorded or manually written.
And yes you can call both subs and functions (with respect to
public/private)
6. Yes. You have to reference the workbook for this.


--
Regards
Frank Kabel
Frankfurt, Germany


Hari wrote:
Hi,

For the last couple of days I have been indiscriminately pinching
codes from NG and pasting it in to This workbook or by inserting new
modules without understanding which should be used for what.

I am a newbie and want to learn VBA with excel.

Couple of questions based on this:-

1. What is the difference between Sub, Function, Module and code.

2. If I get a code ( from NG) where should I add it . Should I add it
"This workbook" or a new module. If possible please tell me in what
circumstances one should be adding the code in which of the above 2

3. What is the difference between Public, private with reference to
both sub and function.

4. When do we add codes to "Sheet1" rather than workbook.

5. Based on info from newsgroups I learned that a Macro/Module ( I
believe macro is recorded and module is anything which is written,
please correct me if am wrong) could be called. Can we call both a
macro and function from another function/macro

6. Can a module in sheet call a module in another shet/workbook or
from module 1.

Please guide me to the right source for learing these bsic concepts

if
possible.

Regards,
Hari
India