Option Private Module Statement


Option Private Module


Restricts the scope and visibility of the contents of a module (i.e., its variables, classes, functions, and procedures) in VBA-enabled applications that allow references across multiple projects (e.g., Microsoft Office applications) to the module's project. Option Private Module has no effect in the standalone version of Visual Basic.

Rules at a Glance

• The Option Private Module statement must appear in the declarations section of a module before any procedures.

446 Chapter 7- The Language Reference

• Publicly declared procedures, variables, and objects contained within a module that has been set as private using the Option Private Module statement aren't available to other projects and applications. However, they are still available in the usual way to other members of the same project.

Programming Tips & Gotchas

You should only use the Option Private Module statement in applications such as Microsoft Excel that allow you to load multiple projects. In this way, the Option Private Module statement restricts visibility of publicly declared items.

+1 0

Post a comment