PDA

View Full Version : Solved: What is the diffrence between Private Sub and just Sub in a macro



softman
08-10-2011, 01:00 PM
I am new to VBA and do not know the difference between "Private Sub" and just "Sub" in a macro or where or when to use it, Any quick help please?

Rob342
08-10-2011, 02:13 PM
Hi Softman
Save me explaining
If you highlight the Sub or Private sub in a piece of code, then key F1 the microsoft help file will explain all.

Rob

Kenneth Hobs
08-10-2011, 02:23 PM
A Sub is Public unless it set as Private. Private Subs are not listed in the macros that can be ran. These are usually set for you when you use an Event for example. Note the Userform code is Private for the objects since they have events. A Class typically has some Private Subs. A module can have a Private Sub if it is used just in that Sub. Most Module code is typically Public.

softman
08-17-2011, 01:34 PM
Many thanks Kenneth, great explanation.