Home
FREE DOWNLOADS
VBA Tutorials
VBA Code Samples
VBA for Beginners
Save Time on PC
SaveTimeWebsite
Save Time News
Save Time Blog
SaveTime SiteMap
Customer Service
Gibberish
Improve Quality

Subscribe To
This Site

XML RSS
Add to Google
Add to My Yahoo!
Add to My MSN
Add to Newsgator
Subscribe with Bloglines


VBA Private Sub and Public Sub

A VBA Private Sub can only be called from anywhere in the Module in which it resides. A Public Sub in the objects, ThisWorkbook, ThisDocument, Sheet1, etc. cannot be called from anywhere in a project.

Aside from Private and Public, you may also declare a Subroutine as Static. If you declare a Sub as Static, all the variables declared within the Sub will retain their values when the Sub is exited instead of the default behavior, which is that they become Empty and their value "out of context." Thus, their value is not preserved.

Variables that are used in a Sub are always Local to the Sub unless they are explicitly declared at the Module level. Module level variables are those declared above the first Sub procedure in a Module and they retain their value throughout the Module. This is the case where the variable has been declared with the Dim Keyword...

However, if you declare a Module level variable with the Public Keyword it can be used anywhere in the project and retains its value.



Google


Return from VBA Private Sub to VBA Code Samples


Return to our Homepage


footer for Save Time page