| Option Private Module Statement |
Syntax
Option Private Module
Description
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.
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 and 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.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access