Home » excel » Hide VBA procedures from Excel application but not from other projects

Hide VBA procedures from Excel application but not from other projects

Posted by: admin April 23, 2020 Leave a comment

Questions:

I know this is a long shot, but with the limitations in “Option Private Module” and even worse “Private Sub/Function”, does anyone know if there is a way of hiding VBA procedures from the Excel application but not from other projects?

I have an XLAM with a subset of reusable functionality that I like to include and reference from new Excel projects, but using “Option Private Module” hinders this and if I omit it, a bunch of unusable or obscure functions and subs become visible and available to the application.

How to&Answers:
  • Convert your standard modules in the XLAM to class modules (set to
    Public Not Creatable);
  • Create an additional Class Module that returns an instance (with a
    bit of additional work, the instance) of each such module; and
  • Create a single standard module with one property that returns the instance of the main class-entry module.

Class1:

Option Explicit

Public Sub IAmInvisible()

End Sub

ModuleEntry:

Option Explicit

Private mClass As New Class1

Public Property Get TheClass() As Class1
    Set TheClass = mClass
End Property