Visual Basic for Applications Reference

Option Private Statement

See Also Example Specifics

When used in host applications that allow references across multiple projects, Option Private Module prevents a modules contents from being referenced outside its project. In host applications that dont permit such references, for example, standalone versions of Visual Basic, Option Private has no effect.


Option Private Module


If used, the OptionPrivate statement must appear at module level, before any procedures.

When a module contains Option Private Module, the public parts, for example, variables, objects, and user-defined types declared at module level, are still available within the project containing the module, but they are not available to other applications or projects.

*Note* Option Private is only useful for host applications that support simultaneous loading of multiple projects and permit references between the loaded projects. For example, Microsoft Excel permits loading of multiple projects and Option Private Module can be used to restrict cross-project visibility. Although Visual Basic permits loading of multiple projects, references between projects are never permitted in Visual Basic.