View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips Bob Phillips is offline
external usenet poster
 
Posts: 10,593
Default Declaring subs Public vs Private

A private sub can only be called from within the procedure that it is
within. Such procedures will not be seen from within the macro list.

A public sub can be called from any module, within that project or any other
project. Such procedures will be seen from within the macro list, unless the
procedure has arguments, in which case it won't. However, if the option,
Option Private Module is also used, even Public subs cannot be called from
another project, and will not be seen within the macro list.

Functions are not shown in the macro list, whether they are private or
public.

If the sub is within a class module, it has to be preceded with the class
name even if it is public. So you can make the Workbook_Open procedure
public, it is normally private by default, and call it from within the same
project using ThisWorkbook!Workbook_Open.

--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)



"Rick" wrote in message
...
When is it correct to declare a sub Public vs Private? What is the
advantage?