Procedure Scope

Just like variables, procedures have scope, which controls the parts of the project from where the procedure can be called. Procedure scope is controlled by the use of the Public and Private keywords in the procedure definition, and by the Option Private statement. There are three possibilities:

  • A public procedure is visible to code in all other modules in all projects. To make a procedure public, use the Public keyword in the procedure definition, or use no keyword as public is the default scope:

    Public Sub MySub()
    
  • A private procedure is visible only to code within its own module. To make a procedure private, use the Private keyword in the procedure definition:

    Private Sub MySub()
    
  • If the Option Private statement is present in ...

Get Office® XP Development with VBA now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.