public sub and private sub

Hi Experts

What is the difference between a Public Sub and Private Sub. and when do you use them and under what circumstances...........

route217Asked:
Who is Participating?
 
gtglonerConnect With a Mentor Commented:
In both Function and Sub procedures, the Public keyword allows the procedure to be called by any other procedure, in any code module.  The Private keyword indicates that the procedure may be called only by procedures in the same code module.  Public   is the default.

0
 
Saurabh Singh TeotiaConnect With a Mentor Commented:
The difference between public and private is when you do alt+f8 over the workbook, You will be able to see all the codes which are there in the workbook which are public, However all the private codes dont show in that list, The advantage that i can tell you that its a way that you can hide the code in your workbook and protect the vb editor as well and if user does alt+f8 over your workbook he wont get any macro list even being the macro there.
0
 
route217Author Commented:
THANKS FOR THE FEEDBACK......experts
0
 
Rory ArchibaldConnect With a Mentor Commented:
Small clarification: the Public modifier allows the code to be called directly from any routine in any module *in the same project*. In order to call between projects you need to either set a reference to the workbook with the code or use Application.Run (which will also work with Private subs in normal modules bizarrely).
0
All Courses

From novice to tech pro — start learning today.